XLOOKUP on Array with Same Entity on Multiple Lines

chasfh

Board Regular
Joined
Dec 10, 2014
Messages
64
Office Version
  1. 365
Platform
  1. Windows
I am trying to add classifications to my leagues based on year. Some leagues change classifications on a year-to-year basis.

I am trying to use XLOOKUP to look up the year and the league, and select the proper classification from a range.

The problem arises when a league changes classifications from year to year, and I end up with the same league name on multiple lines. See the example below.

I tried an array XLOOKUP:

=XLOOKUP(A4&B4,$F$3:$P$3&$E$4:$E$8,$F$4:$P$8))

... and I get #VALUE! for all the results.

Then I tried a nested XLOOKUP (the one on the XL2BB sheet below):

=XLOOKUP(A4,$F$3:$P$3,XLOOKUP(B4,$E$4:$E$8,$F$4:$P$8))

... and it works fine on leagues that never change classifications, but not on leagues that do. With leagues that do, it gives me correct results from the first line, but zeroes as the result on subsequent lines.

Obviously, I would have believed that even with multiple lines of the same league, it would look for the classification that matches the year properly, but apparently, as currently constructed, XLOOKUP doesn't work that way.

Please don't suggest I simply consolidate lines that have multiple leagues because there are hundreds of them, which will take me hours, and I'd rather not have to do that until we determine there is no solution for this.

Thanks!

YearLeagueClass19341935193619371938193919401941194219431944
1934InternationalBInternationalBBBBB
1934South AtlanticCAmericanCCCC
1935InternationalBSouth AtlanticCCC
1935South AtlanticCSouth AtlanticBBBB
1936InternationalBSouth AtlanticAAAA
1936South AtlanticC
1937InternationalB
1937South Atlantic0
1938InternationalB
1938South Atlantic0
1939South Atlantic0
1940South Atlantic0
1941AmericanC
1941South Atlantic0
1942AmericanC
1942South Atlantic0
1943AmericanC
1943South Atlantic0
1944AmericanC
1944South Atlantic0
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How about this?

Book2
ABCDEFGHIJKLMNOP
1YearLeagueClass19341935193619371938193919401941194219431944
21934InternationalBInternationalBBBBB      
31934South AtlanticCAmerican       CCCC
41935InternationalBSouth AtlanticCCC00000000
51935South AtlanticCSouth AtlanticCCC00000000
61936InternationalBSouth AtlanticCCC00000000
71936South AtlanticC
81937InternationalB
91937South Atlantic0
101938InternationalB
111938South Atlantic0
121939South Atlantic0
131940South Atlantic0
141941AmericanC
151941South Atlantic0
161942AmericanC
171942South Atlantic0
181943AmericanC
191943South Atlantic0
201944AmericanC
211944South Atlantic0
Sheet1
Cell Formulas
RangeFormula
F2:P6F2=IFERROR(XLOOKUP(F$1&$E2,$A$2:$A$21&$B$2:$B$21,$C$2:$C$21),"")
 
Upvote 0
If you want to get rid of the ZERO returns, use this in Cell F2
=LET(Class,IFERROR(XLOOKUP(F$1&$E2,$A$2:$A$21&$B$2:$B$21,$C$2:$C$21),""),IF(Class=0,"",Class))
 
Upvote 0
If you want to get rid of the ZERO returns, use this in Cell F2
=LET(Class,IFERROR(XLOOKUP(F$1&$E2,$A$2:$A$21&$B$2:$B$21,$C$2:$C$21),""),IF(Class=0,"",Class))

I'm sorry, I may not have articulated the problem as properly as I might have.

The problem is not that zeroes are showing up instead of blanks; or that South Atlantic changes to B and then to A in the array. South Atlantic is supposed to change to B then A in the array, not remain C, or change to zeroes or blanks.

The problem is that when South Atlantic does change in the array to B in 1937, the result in cell C11 in the table (and C12 and C13) is a zero, when it should be B, as per the array. And then, when South Atlantic changes to A in 1941, the result in C17 (and C19 AND C21 AND C23) is a zero, when it should be A. I am not trying to change all the Bs and As in the array for South Atlantic to zeroes or blanks. They are supposed to stay that way in the array. What I am trying to change is the result in the table.

There are multiple rows for South Atlantic because that's the way the table came together from an outside source. But there is no duplication for South Atlantic at any time; South Atlantic is never B on one row and C on another row in the same year (column). There's mutual exclusivity. That's why I am trying to have the XLOOKUP read the array to deliver the different classifications for the different years, even if the league is listed on multiple rows. Consolidating all the teams listed on multiple rows—and there are a couple hundred of them—into single rows for each would take hours and hours of manual labor. That's what I'm trying to avoid.

Knowing that now, is there any way to accomplish what I am trying to?
 
Last edited:
Upvote 0
Ok, I'll step back and ask this question. Are you trying to populate the Table in Columns E through P with the Data in Columns A through C?
 
Upvote 0
Ok, I'll step back and ask this question. Are you trying to populate the Table in Columns E through P with the Data in Columns A through C?

Other way around. I am trying to populate Column C with data from the array E3:P8, based on the lookup values in Column A (year) and Column B (league).

So, in row 9, based on the lookup values in cell A9 (1937) and cell B9 (South Atlantic), I want it to go the the array and pull the letter "B", which is where the two values intersect in the array in cell I5, and return that "B" to cell C9.

I tried both of the formulas in the original post and neither of them worked for me.

Thanks for checking up on that. Any ideas based on it?
 
Upvote 0
Please try this

Book2
ABCDEFGHIJKLMNOP
1YearLeagueClass19341935193619371938193919401941194219431944
21934InternationalBInternationalBBBBB
31934South AtlanticCAmericanCCCC
41935InternationalBSouth AtlanticCCC
51935South AtlanticCSouth AtlanticBBBB
61936InternationalBSouth AtlanticAAAA
71936South AtlanticC
81937InternationalB
91937South AtlanticB
101938InternationalB
111938South AtlanticB
121939South AtlanticB
131940South AtlanticB
141941AmericanC
151941South AtlanticA
161942AmericanC
171942South AtlanticA
181943AmericanC
191943South AtlanticA
201944AmericanC
211944South AtlanticA
Sheet1
Cell Formulas
RangeFormula
C2:C21C2=TEXTJOIN(,TRUE,FILTER(INDEX($F$2:$P$6,,MATCH($A2,$F$1:$P$1)),($E$2:$E$6=$B2)))
 
Upvote 0
Any zeros in the right table will need to be removed. The formula works to remove blank cells. Search and replace entire cell contents for any zeros and replace with nothing.
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHIJKLMNOP
1YearLeagueClass19341935193619371938193919401941194219431944
21934InternationalBInternationalBBBBB
31934South AtlanticCAmericanCCCC
41935InternationalBSouth AtlanticCCC
51935South AtlanticCSouth AtlanticBBBB
61936InternationalBSouth AtlanticAAAA
71936South AtlanticC
81937InternationalB
91937South AtlanticB
101938InternationalB
111938South AtlanticB
121939South AtlanticB
131940South AtlanticB
141941AmericanC
151941South AtlanticA
161942AmericanC
171942South AtlanticA
181943AmericanC
191943South AtlanticA
201944AmericanC
211944South AtlanticA
22
Data
Cell Formulas
RangeFormula
A2:C21A2=SORT(HSTACK(TOCOL(IF(F2:P6<>"",F1:P1,1/0),2),TOCOL(IF(F2:P6<>"",E2:E6,1/0),2),TOCOL(F2:P6,1)))
Dynamic array formulas.
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHIJKLMNOP
1YearLeagueClass19341935193619371938193919401941194219431944
21934InternationalBInternationalBBBBB
31934South AtlanticCAmericanCCCC
41935InternationalBSouth AtlanticCCC
51935South AtlanticCSouth AtlanticBBBB
61936InternationalBSouth AtlanticAAAA
71936South AtlanticC
81937InternationalB
91937South AtlanticB
101938InternationalB
111938South AtlanticB
121939South AtlanticB
131940South AtlanticB
141941AmericanC
151941South AtlanticA
161942AmericanC
171942South AtlanticA
181943AmericanC
191943South AtlanticA
201944AmericanC
211944South AtlanticA
22
Data
Cell Formulas
RangeFormula
A2:C21A2=SORT(HSTACK(TOCOL(IF(F2:P6<>"",F1:P1,1/0),2),TOCOL(IF(F2:P6<>"",E2:E6,1/0),2),TOCOL(F2:P6,1)))
Dynamic array formulas.

Not sure I'm doing it right, but I am getting a #SPILL! error.

1709233836485.png
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
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