Array formula to show in matrix form data from table?

Fractalis

Active Member
Joined
Oct 11, 2011
Messages
328
Office Version
  1. 365
Platform
  1. Windows
Having a table like below with 3 columns, is possible with an array formula to show dynamically which countries (Country Abbreviation) are related for
each medal type (gold, silver, bronze) and season? below is shown countries for each season, when in cell is entered "Gold". In this example, the output
is shown in a range of 2x3 cells. But if the countries are more than 50, should be shown for example in a range of 17 rows x 3 columns.

If only via VBA maybe someone could help me out. Thanks in advance.

SeasonCountryCountry AbbrTypeTypeGold
SummerChinaCHNGold
SummerFranceFRAGoldSEASON
SummerGreat BritainGBRGoldSummerWinter
SummerSoviet UnionURSGoldCHNFRAGBRAUTCANGER
SummerUnited StatesUSAGoldURSUSANORURSUSA
SummerGermanyGERSilver
SummerHungaryHUNSilver
SummerItalyITASilver
SummerJapanJPNSilver
SummerAustraliaAUSBronze
SummerEast GermanyGDRBronze
SummerFinlandFINBronze
SummerRussiaRUSBronze
SummerSwedenSWEBronze
WinterAustriaAUTGold
WinterCanadaCANGold
WinterGermanyGERGold
WinterNorwayNORGold
WinterSoviet UnionURSGold
WinterUnited StatesUSAGold
WinterNetherlandsNEDSilver
WinterSwedenSWESilver
WinterSwitzerlandSUISilver
WinterEast GermanyGDRBronze
WinterFinlandFINBronze
WinterFranceFRABronze
WinterItalyITABronze
WinterRussiaRUSBronze
WinterSouth KoreaKORBronze


Below how would be the output when "Silver" and "Bronze" are entered.

TypeSilver
SEASON
SummerWinter
GERHUNITANEDSWESUI
JPN


TypeBronze
SEASON
SummerWinter
AUSGDRFINGDRFINFRA
RUSSWEITARUSKOR
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
With dynamic array formulas.

Book1
ABCDEFGHIJKL
1SeasonCountryCountry AbbrTypeTypeGold
2SummerChinaCHNGold
3SummerFranceFRAGoldSEASON
4SummerGreat BritainGBRGoldSummerWinter
5SummerSoviet UnionURSGoldCHNFRAGBRAUTCANGER
6SummerUnited StatesUSAGoldURSUSANORURSUSA
7SummerGermanyGERSilver
8SummerHungaryHUNSilver
9SummerItalyITASilver
10SummerJapanJPNSilver
11SummerAustraliaAUSBronze
12SummerEast GermanyGDRBronze
13SummerFinlandFINBronze
14SummerRussiaRUSBronze
15SummerSwedenSWEBronze
16WinterAustriaAUTGold
17WinterCanadaCANGold
18WinterGermanyGERGold
19WinterNorwayNORGold
20WinterSoviet UnionURSGold
21WinterUnited StatesUSAGold
22WinterNetherlandsNEDSilver
23WinterSwedenSWESilver
24WinterSwitzerlandSUISilver
25WinterEast GermanyGDRBronze
26WinterFinlandFINBronze
27WinterFranceFRABronze
28WinterItalyITABronze
29WinterRussiaRUSBronze
30WinterSouth KoreaKORBronze
Sheet1
Cell Formulas
RangeFormula
F5:H6,J5:L6F5=LET(f,FILTER($A$2:$D$30,($A$2:$A$30=F4)*($D$2:$D$30=$G$1),""),r,ROUNDUP(ROWS(f)/3,0),IFERROR(INDEX(f,SEQUENCE(r,3),3),""))
Dynamic array formulas.
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

If all functions are available to you then you could also consider:

22 11 02.xlsm
ABCDEFGHIJKL
1SeasonCountryCountry AbbrTypeTypeGold
2SummerChinaCHNGold
3SummerFranceFRAGoldSEASON
4SummerGreat BritainGBRGoldSummerWinter
5SummerSoviet UnionURSGoldCHNFRAGBRAUTCANGER
6SummerUnited StatesUSAGoldURSUSANORURSUSA
7SummerGermanyGERSilver
8SummerHungaryHUNSilver
9SummerItalyITASilver
10SummerJapanJPNSilver
11SummerAustraliaAUSBronze
12SummerEast GermanyGDRBronze
13SummerFinlandFINBronze
14SummerRussiaRUSBronze
15SummerSwedenSWEBronze
16WinterAustriaAUTGold
17WinterCanadaCANGold
18WinterGermanyGERGold
19WinterNorwayNORGold
20WinterSoviet UnionURSGold
21WinterUnited StatesUSAGold
22WinterNetherlandsNEDSilver
23WinterSwedenSWESilver
24WinterSwitzerlandSUISilver
25WinterEast GermanyGDRBronze
26WinterFinlandFINBronze
27WinterFranceFRABronze
28WinterItalyITABronze
29WinterRussiaRUSBronze
30WinterSouth KoreaKORBronze
Fractalis
Cell Formulas
RangeFormula
F5:H6,J5:L6F5=WRAPROWS(TRANSPOSE(FILTER($C$2:$C$30,($A$2:$A$30=F4)*($D$2:$D$30=$G$1),"")),3,"")
Dynamic array formulas.
 
Upvote 0
Thanks both Jason/Peter for your help. Even I use office 365, the machine where I need to use this has Excel profesional plus 2019 and it seems doesn't have these functions available. Is there an alternative solution for Excel 2019?
 
Upvote 0
Try:

Book1
ABCDEFGHIJKL
1SeasonCountryCountry AbbrTypeTypeGold
2SummerChinaCHNGold
3SummerFranceFRAGoldSEASON
4SummerGreat BritainGBRGoldSummerWinter
5SummerSoviet UnionURSGoldCHNFRAGBRAUTCANGER
6SummerUnited StatesUSAGoldURSUSA NORURSUSA
7SummerGermanyGERSilver      
8SummerHungaryHUNSilver      
9SummerItalyITASilver
10SummerJapanJPNSilver
11SummerAustraliaAUSBronze
12SummerEast GermanyGDRBronze
13SummerFinlandFINBronze
14SummerRussiaRUSBronze
15SummerSwedenSWEBronze
16WinterAustriaAUTGold
17WinterCanadaCANGold
18WinterGermanyGERGold
19WinterNorwayNORGold
20WinterSoviet UnionURSGold
21WinterUnited StatesUSAGold
22WinterNetherlandsNEDSilver
23WinterSwedenSWESilver
24WinterSwitzerlandSUISilver
25WinterEast GermanyGDRBronze
26WinterFinlandFINBronze
27WinterFranceFRABronze
28WinterItalyITABronze
29WinterRussiaRUSBronze
30WinterSouth KoreaKORBronze
Sheet3
Cell Formulas
RangeFormula
F5:H8F5=IFERROR(INDEX($C:$C,AGGREGATE(15,6,ROW($C$2:$C$50)/($D$2:$D$50=$G$1)/($A$2:$A$50=$F$4),(ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5))),"")
J5:L8J5=IFERROR(INDEX($C:$C,AGGREGATE(15,6,ROW($C$2:$C$50)/($D$2:$D$50=$G$1)/($A$2:$A$50=$J$4),(ROWS($J$5:$J5)-1)*3+COLUMNS($J5:J5))),"")
 
Upvote 0
Solution
Thanks so much Eric W. It works perfectly. If I change "..(ROWS($F$5:$F5)-1)*3.." to for example "..(ROWS($F$5:$F5)-1)*8.." or any number, I could extend the number of columns
accordingly right?

If you have a chance to add a little explanation of how the logic of the formula works, would be great.
 
Upvote 0
That's correct! The formula is pretty simple, although you might not have seen this type of formula before:

=IFERROR(INDEX($C:$C,AGGREGATE(15,6,ROW($C$2:$C$50)/($D$2:$D$50=$G$1)/($A$2:$A$50=$F$4),(ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5))),"")

We start with the row numbers of the countries. We'll get an array of 49 row numbers.

=IFERROR(INDEX($C:$C,AGGREGATE(15,6,ROW($C$2:$C$50)/($D$2:$D$50=$G$1)/($A$2:$A$50=$F$4),(ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5))),"")

Now we divide those row numbers by ($D$2:$D$50=$G$1) which gives us an array of TRUE/FALSE values based on whether column D has the same value as G1. When computing with TRUE/FALSE values, Excel treats TRUE as 1, and FALSE as 0. So once we divide the 1/0 into the row number, we'll either get the row number again, or a #DIV/0 error. We then repeat with the green section, checking for the season in column A. After that, we're left with an array of row numbers that match our conditions, or #DIV/0 errors.

At this point, AGGREGATE kicks in. the 15 means SMALL, and the 6 means ignore errors. So if we can create a counter from 1 to n, we can extract just the row numbers. The (ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5) part does that. The ROWS counts how many rows we've done so far, and we multiply by the number of columns we want (3 in this case, but 8 works as you expect), and add in the number of columns. This creates a counter from 1-n, progressing by columns first, then down by rows. So each cell in your output table gives a different value to AGGREGATE (SMALL) and gets a different row number, which then goes to INDEX to get it.

The IFERROR kicks in when the counter exceeds the number of matching rows.

Hope this helps!
 
Upvote 0
That's correct! The formula is pretty simple, although you might not have seen this type of formula before:

=IFERROR(INDEX($C:$C,AGGREGATE(15,6,ROW($C$2:$C$50)/($D$2:$D$50=$G$1)/($A$2:$A$50=$F$4),(ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5))),"")

We start with the row numbers of the countries. We'll get an array of 49 row numbers.

=IFERROR(INDEX($C:$C,AGGREGATE(15,6,ROW($C$2:$C$50)/($D$2:$D$50=$G$1)/($A$2:$A$50=$F$4),(ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5))),"")

Now we divide those row numbers by ($D$2:$D$50=$G$1) which gives us an array of TRUE/FALSE values based on whether column D has the same value as G1. When computing with TRUE/FALSE values, Excel treats TRUE as 1, and FALSE as 0. So once we divide the 1/0 into the row number, we'll either get the row number again, or a #DIV/0 error. We then repeat with the green section, checking for the season in column A. After that, we're left with an array of row numbers that match our conditions, or #DIV/0 errors.

At this point, AGGREGATE kicks in. the 15 means SMALL, and the 6 means ignore errors. So if we can create a counter from 1 to n, we can extract just the row numbers. The (ROWS($F$5:$F5)-1)*3+COLUMNS($F5:F5) part does that. The ROWS counts how many rows we've done so far, and we multiply by the number of columns we want (3 in this case, but 8 works as you expect), and add in the number of columns. This creates a counter from 1-n, progressing by columns first, then down by rows. So each cell in your output table gives a different value to AGGREGATE (SMALL) and gets a different row number, which then goes to INDEX to get it.

The IFERROR kicks in when the counter exceeds the number of matching rows.

Hope this helps!
It helps a lot!!! and certainly will help to more than one person in the future when they look for a similar solution. Thanks Eric W.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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