Transpose using formulas based on condition

Sumit_123

New Member
Joined
Oct 5, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi, I have a situation where in I have data where the hierarchy goes as follows
Region>Country>Plant>crusher Name>Machine Score>Machine score check date.
1633492928906.png

is there a way to transpose the score 1 date below the most recent score column and the date next to it using formulas and likewise for other columns for score 3 date and etc..?
The catch is that the columns from A:E should be repeated for Score1 and date and likewise for score2 and date .
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
If I am understanding you correctly, yes if you use some math! But you have to have an index column (just an extra column counting). And of course the table that you want to see transposes in needs to be separate from the original data table. (And for this to work the index column must start at 2. But the table can be moved around in the sheet . . . but the two tables need to start on the same row, so I meant move both tables around on the sheet.)

Blank33.xlsb
ABCDEFGHIJKLMNOPQRSTUVWX
1RegionCountryPlantCrusher NameCrusher TypeMost Recent scoreMost Recent Score DateRegionCountryPlantCrusher NameCrusher TypeMost Recent scoreMost Recent Score DateScore 1Score 1 DateScore 2Score 2 DateScore 3Score 3 DateScore 4Score 4 DateINDEX COLUMN
2APACMalaysAirSvedala JX9412/4/2021APACMalaysAirSvedala JX9412/4/2021908/23/2020858/24/2020878/25/2020928/27/20202
3APACMalaysAirSvedala JX908/23/2020A_regA_coutryA_pA_cnA52ADATE_REC53ADATE155ADATE250ADATE349ADATE43
4APACMalaysAirSvedala JX858/24/2020B_regB_coutryB_pB_cnB61BDATE_REC64BDATE162BDATE264BDATE366BDATE44
5APACMalaysAirSvedala JX878/25/2020C_regC_coutryC_pC_cnC32CDATE_REC35CDATE139CDATE231CDATE330CDATE45
6APACMalaysAirSvedala JX928/27/2020D_regD_coutryD_pD_cnD72DDATE_REC75DDATE170DDATE279DDATE371DDATE46
7A_regA_coutryA_pA_cnA52ADATE_REC7
8A_regA_coutryA_pA_cnA53ADATE18
9A_regA_coutryA_pA_cnA55ADATE29
10A_regA_coutryA_pA_cnA50ADATE310
11A_regA_coutryA_pA_cnA49ADATE411
12B_regB_coutryB_pB_cnB61BDATE_REC12
13B_regB_coutryB_pB_cnB64BDATE113
14B_regB_coutryB_pB_cnB62BDATE214
15B_regB_coutryB_pB_cnB64BDATE315
16B_regB_coutryB_pB_cnB66BDATE4
17C_regC_coutryC_pC_cnC32CDATE_REC
18C_regC_coutryC_pC_cnC35CDATE1
19C_regC_coutryC_pC_cnC39CDATE2
20C_regC_coutryC_pC_cnC31CDATE3
21C_regC_coutryC_pC_cnC30CDATE4
22D_regD_coutryD_pD_cnD72DDATE_REC
Sheet8 (3)
Cell Formulas
RangeFormula
F2:F22F2=SWITCH(MOD(ROW()-2,5),0,INDEX($N$2:$N$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),1,INDEX($P$2:$P$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),2,INDEX($R$2:$R$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),3,INDEX($T$2:$T$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),4,INDEX($V$2:$V$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0))
G2:G22G2=SWITCH(MOD(ROW()-2,5),0,INDEX($O$2:$O$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),1,INDEX($Q$2:$Q$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),2,INDEX($S$2:$S$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),3,INDEX($U$2:$U$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0),4,INDEX($W$2:$W$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0))
A2:E22A2=INDEX($I$2:$M$6,MATCH(FLOOR((ROW()+3)/5,1)+1,$X$2:$X$6,0),0)
Dynamic array formulas.
 
Last edited:
Upvote 0
Thankyou so much for replying. The solution you provided is exactly what I am looking for but I am not very much advanced in excel. The situation I have is that I have other columns as well in between which I didn't included in the example above(genuine apologies for this).
Because I am not too much advanced in excel I am failing to understand how should I manipulate or what changes in the formula I should be making to address my situation. Can you please guide me in this situation.
Thanks again
 
Upvote 0
Thankyou so much for replying. The solution you provided is exactly what I am looking for but I am not very much advanced in excel. The situation I have is that I have other columns as well in between which I didn't included in the example above(genuine apologies for this).
Because I am not too much advanced in excel I am failing to understand how should I manipulate or what changes in the formula I should be making to address my situation. Can you please guide me in this situation.
Thanks again
What's better than a video? It's 19 minutes long, but I will walk you through each step (to the best of my ability).

Let me know if you have any further questions. And if you have a question about a specific part of the video, just let me know. (For all others reading, the gist of the video is to make use of Excel table objects.)
 
Upvote 0
Solution
Another option
+Fluff 1.xlsm
ABCDEFGHIJKLMNOPQR
1RegionCountryPlantCrusher NameCrusher TypeabcdefghiMost Recent scoreMost Recent Score DateScore 1Score 1 DateScore 2Score 2 DateScore 3Score 3 DateScore 4Score 4 Date
2APACMalaysAirSvedala JXData 1Data 10Data 209401/01/20219001/02/20218501/03/20218701/04/2021
3A_regA_coutryA_pA_cnAData 2Data 11Data 215211/01/20215311/02/20215511/03/20215011/04/20214911/05/2021
4B_regB_coutryB_pB_cnBData 3Data 12Data 226121/01/20216421/02/20216221/03/20216421/04/20216621/05/2021
5C_regC_coutryC_pC_cnCData 4Data 13Data 233231/01/20213503/03/20213931/03/2021
6D_regD_coutryD_pD_cnDData 5Data 14Data 247210/02/20217513/03/20217010/04/20217911/05/20217110/06/2021
7
8
9
10
11
12
13
14APACMalaysAirSvedala JXData 1Data 10Data 209401/01/2021
15APACMalaysAirSvedala JXData 1Data 10Data 209001/02/2021
16APACMalaysAirSvedala JXData 1Data 10Data 208501/03/2021
17APACMalaysAirSvedala JXData 1Data 10Data 208701/04/2021
18A_regA_coutryA_pA_cnAData 2Data 11Data 215211/01/2021
19A_regA_coutryA_pA_cnAData 2Data 11Data 215311/02/2021
20A_regA_coutryA_pA_cnAData 2Data 11Data 215511/03/2021
21A_regA_coutryA_pA_cnAData 2Data 11Data 215011/04/2021
22A_regA_coutryA_pA_cnAData 2Data 11Data 214911/05/2021
23B_regB_coutryB_pB_cnBData 3Data 12Data 226121/01/2021
24B_regB_coutryB_pB_cnBData 3Data 12Data 226421/02/2021
25B_regB_coutryB_pB_cnBData 3Data 12Data 226221/03/2021
26B_regB_coutryB_pB_cnBData 3Data 12Data 226421/04/2021
27B_regB_coutryB_pB_cnBData 3Data 12Data 226621/05/2021
28C_regC_coutryC_pC_cnCData 4Data 13Data 233231/01/2021
29C_regC_coutryC_pC_cnCData 4Data 13Data 233503/03/2021
30C_regC_coutryC_pC_cnCData 4Data 13Data 233931/03/2021
31D_regD_coutryD_pD_cnDData 5Data 14Data 247210/02/2021
32D_regD_coutryD_pD_cnDData 5Data 14Data 247513/03/2021
33D_regD_coutryD_pD_cnDData 5Data 14Data 247010/04/2021
34D_regD_coutryD_pD_cnDData 5Data 14Data 247911/05/2021
35D_regD_coutryD_pD_cnDData 5Data 14Data 247110/06/2021
36
Lists
Cell Formulas
RangeFormula
A14:H35A14=LET(RngA,A2:H6, RngB,I2:R6,Rws,ROWS(RngA),Qty,SEQUENCE(Rws*COLUMNS(RngB)/2,,0),AryA,INDEX(RngA,INT(Qty/Rws)+1,MOD(Qty,Rws)*0+SEQUENCE(,COLUMNS(RngA))),AryB,INDEX(RngB,INT(Qty/Rws)+1,MOD(Qty,Rws)*2+{1,2}),FILTER(AryA,INDEX(AryB,,1)<>""))
I14:J35I14=LET(RngB,I2:R6,Rws,ROWS(RngB),Qty,SEQUENCE(Rws*COLUMNS(RngB)/2,,0),AryB,INDEX(RngB,INT(Qty/Rws)+1,MOD(Qty,Rws)*2+{1,2}),FILTER(AryB,INDEX(AryB,,1)<>""))
Dynamic array formulas.
 
Upvote 0
For those who are curious, in the video I set up a design which removed the dynamic array formulas from my first post. In this one minute (follow-up) video (it had to be 20 minutes, I guess! LOL), I show how to remove the one (unnecessary) dynamic array formula (for the table headers display).

So an index column doesn't have to be displayed with this approach, but just used in the Excel Table object where the data is inputted in.

Also, I posted an image rather than using XL2BB because XL2BB does a poor job of representing the formulas in this sheet. So I list the three formulas that are in a cell which (in the videos) I show that I: place them in a cell to the left, filled them right, and then filled all of those down.

(And note that Table5 is in another sheet. Its header row is also on row 1, but either of the "table" of formulas or the Excel table object can be shifted horizontally left or right.)

Formula in A1. Filled right to O1.
Excel Formula:
=Table5[[#Headers],[Region]]

Formula in A2. Filled right to O2, but then deleted in F2 and G2. (And of course cells with this formula were then filled down.)
Excel Formula:
=INDEX(Table5[Region],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0)

Formula in F2. Filled right to G2. (And then the two cells were filled down.)
Excel Formula:
=SWITCH(MOD(ROW()-2,5),0,INDEX(Table5[Most Recent score],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),1,INDEX(Table5[Score 1],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),2,INDEX(Table5[Score 2],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),3,INDEX(Table5[Score 3],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),4,INDEX(Table5[Score 4],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0))

And speaking of which (I mean "SWITCH"), I guess I should make this completely transferrable to other versions of Office besides 365 if I convert it into a nested IF statement:
Excel Formula:
=IF(MOD(ROW()-2,5) = 0, INDEX(Table5[Most Recent score],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
IF(MOD(ROW()-2,5) = 1,INDEX(Table5[Score 1],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
IF(MOD(ROW()-2,5) = 2,INDEX(Table5[Score 2],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
IF(MOD(ROW()-2,5) = 3,INDEX(Table5[Score 3],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
IF(MOD(ROW()-2,5) = 4,INDEX(Table5[Score 4],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0))))))

Final Display Table.PNG
 
Last edited:
Upvote 0
Thanks a lot for such a detailed video. I am really grateful and thankful to you for doing such a great effort. I was able to understand all of it.
Just one quick question that I had - If i had more scores and date what should i be changing in the formula that you provided (like in the image below)?

1633570767996.png


1633570739214.png
As per the image on the left I am getting results for until Score 4 date and then everything is being messed up.
 
Upvote 0
Thanks a lot for such a detailed video. I am really grateful and thankful to you for doing such a great effort. I was able to understand all of it.
Just one quick question that I had - If i had more scores and date what should i be changing in the formula that you provided (like in the image below)?

View attachment 48533

View attachment 48532As per the image on the left I am getting results for until Score 4 date and then everything is being messed up.
You would add to the SWITCH statement.

Following the (long) video's example, let's focus on the Most Recent score column's formula. Once we make a formula for that, we can just fill right to the Most Recent Score Date column to its immediate right.

Right now the Most Recent score formula is the following.

=SWITCH(MOD(ROW()-2,5),
0,INDEX(Table5[Most Recent score],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
1,INDEX(Table5[Score 1],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
2,INDEX(Table5[Score 2],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
3,INDEX(Table5[Score 3],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
4,INDEX(Table5[Score 4],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0)
)

We have 0 through 4 = 5 different possibilities (including most recent score and scores 1-4). And we /5 and have ,5 after "MOD(ROW()-2".

In general, this can be rewritten as the following, where X is the number of scores you have (which is also the number of score dates you have) -- including the most recent . . . so in the example above, X=4, because we had 4 scores in the original image).

=SWITCH(MOD(ROW()-2,5),
0,INDEX(Table5[Most Recent score],MATCH(FLOOR((ROW()+X-1)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
1,INDEX(Table5[Score 1],MATCH(FLOOR((ROW()+X-1)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
2,INDEX(Table5[Score 2],MATCH(FLOOR((ROW()+X-1)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
3,INDEX(Table5[Score 3],MATCH(FLOOR((ROW()+X-1)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0),
4,INDEX(Table5[Score 4],MATCH(FLOOR((ROW()+X-1)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0)
)

If we have the most recent score + scores 1-8, then we would have 0 through 8. And we /9 and have ,9 after "MOD(ROW()-2".
(Also write [Score 1] through [Score 8]. Also X-1 = 8-1 = 7 in this case, since we have 8 scores.)

=SWITCH(MOD(ROW()-2,9),
0,INDEX(Table5[Most Recent score],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
1,INDEX(Table5[Score 1],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
2,INDEX(Table5[Score 2],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
3,INDEX(Table5[Score 3],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
4,INDEX(Table5[Score 4],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
5,INDEX(Table5[Score 5],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
6,INDEX(Table5[Score 6],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
7,INDEX(Table5[Score 7],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0),
8,INDEX(Table5[Score 8],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0)
)

**So this is the formula for Most Recent score column's formula in the first data row of our "visual" table. (For the original/Excel Ctrl T table, you just simply insert the new columns and fill in the data without formulas.)

Therefore, the formula for the cells in the table which repeat will go from what is now (this is the formula for Region, but you fill right to all columns):
=INDEX(Table5[Region],MATCH(FLOOR((ROW()+3)/5,1)+1,Table5[[INDEX]:[INDEX]],0),0)

But it becomes: (making the same numeric changes)
=INDEX(Table5[Region],MATCH(FLOOR((ROW()+7)/9,1)+1,Table5[[INDEX]:[INDEX]],0),0)

**So first take care of REGION's formula, fill right all the way, delete the formulas under More Recent Score and Most Recent Score date, put in the new formula in for most Recent Score, fill right to Most Recent Score Date. (Same as I showed in the video.)

I hope that makes sense!

EDIT:
And change Table5 to whatever your table's name is. Maybe it's Table1? Also, for the SWITCH statement, remove the hard returns (have it all on one line).
 
Upvote 0
Please see my latest edits to that response.

EDIT: Never mind about this post. I made a mistake! It's not that simple! ROW() is in the formula, so that won't work.
 
Last edited:
Upvote 0
Please see my edit to the post above. (Sorry for the confusion!) That "simplification" won't work. I spoke too soon! (The edits to post #8 DO apply. Just what I wrote (but now deleted) in post #9 was wrong.)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top