XLOOKUP with Multiple Criteria?

BrettOlbrys1

Board Regular
Joined
May 1, 2018
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hello. I have two tables. The first table has an "Activation Code" and the "Date" the Activation code was used. The second table is a historical table of data based on that Activation Code.

Table 1
AB
1Activation CodeDate When Code Was Used
2123452/17/22
3123454/4/22
4123458/11/22

Table 2 - Historical Data
ABC
1Activation CodeDateValue
2123451/1/22Northeast
3123453/1/22Southeast
4123456/1/22Central
51234511/1/22West

What I need to do is look up an Activation Code's value from Table 1 based on the date it was used, against the Table 2 historical data, and return whatever the Activation Code's value was at that time.

So the result, when I look up the codes in Table 1, should be:

12345 on 2/17/22 = Northeast
12345 on 4/4/22 = Southeast
12345 on 8/11/22 = Central

How should the formula be constructed?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this formula:
Rich (BB code):
=LET(LFC,A2,LFD,B2,fTab,Sheet2!A1:C20,RESULT,FILTER(INDEX(fTab,0,3),(INDEX(fTab,0,1)=LFC)*(INDEX(fTab,0,2)<=LFD)),INDEX(RESULT,COUNTA(RESULT)))
In this formula the Bold parts have the following meaning:
A2, the cell with the activation code to search
B2, the cell with the searched date
Sheet2!A1:C20, the "Table 2" cells address

Adapt to your situation
 
Upvote 0
Try this formula:
Rich (BB code):
=LET(LFC,A2,LFD,B2,fTab,Sheet2!A1:C20,RESULT,FILTER(INDEX(fTab,0,3),(INDEX(fTab,0,1)=LFC)*(INDEX(fTab,0,2)<=LFD)),INDEX(RESULT,COUNTA(RESULT)))
In this formula the Bold parts have the following meaning:
A2, the cell with the activation code to search
B2, the cell with the searched date
Sheet2!A1:C20, the "Table 2" cells address

Adapt to your situation
Thanks, quick question. Will this work in a Table or does it need to be a range?
Try this formula:
Rich (BB code):
=LET(LFC,A2,LFD,B2,fTab,Sheet2!A1:C20,RESULT,FILTER(INDEX(fTab,0,3),(INDEX(fTab,0,1)=LFC)*(INDEX(fTab,0,2)<=LFD)),INDEX(RESULT,COUNTA(RESULT)))
In this formula the Bold parts have the following meaning:
A2, the cell with the activation code to search
B2, the cell with the searched date
Sheet2!A1:C20, the "Table 2" cells address

Adapt to your situation
Anthony, thanks. It appears this does not work within a Table, only a range, because it froze my sheet when I tried to run it in my Table. Is there a formula that works in a Table so any new results will expand automatically with new data? The formula works as expected for a range.
 
Upvote 0
If Table2 is a structured table then the formula set in the same sheet is table 1 could be:
Rich (BB code):
=LET(LFC,A2,LFD,B2,RESULT,FILTER(Table2[Value],(Table2[Activation Code]=LFC)*(Table2[Date]<=LFD)),INDEX(RESULT,COUNTA(RESULT)))
 
Upvote 0
Assuming both are formal tables, see if this is what you want.

BrettOlbrys1.xlsm
ABC
1Activation CodeDate When Code Was UsedValue at Date
21234517/02/2022Northeast
3123454/04/2022Southeast
41234511/08/2022Central
5
6
7
8Activation CodeDateValue
9123451/01/2022Northeast
10123451/03/2022Southeast
11123451/06/2022Central
12123451/11/2022West
13
14
Sheet1
Cell Formulas
RangeFormula
C2:C4C2=INDEX(SORT(FILTER(Table2,(Table2[Activation Code]=[@[Activation Code]])*(Table2[Date]<=[@[Date When Code Was Used]]),""),2,-1),1,3)
 
Upvote 0
Assuming both are formal tables, see if this is what you want.

BrettOlbrys1.xlsm
ABC
1Activation CodeDate When Code Was UsedValue at Date
21234517/02/2022Northeast
3123454/04/2022Southeast
41234511/08/2022Central
5
6
7
8Activation CodeDateValue
9123451/01/2022Northeast
10123451/03/2022Southeast
11123451/06/2022Central
12123451/11/2022West
13
14
Sheet1
Cell Formulas
RangeFormula
C2:C4C2=INDEX(SORT(FILTER(Table2,(Table2[Activation Code]=[@[Activation Code]])*(Table2[Date]<=[@[Date When Code Was Used]]),""),2,-1),1,3)
Peter, thanks for the formula. My issue with the formula is that when it calculates, it freezes the program because the calculation time is significant. There are currently 120,000 rows of data, and the CPU usage goes to 100%, so how can I do this without it freezing, do you have any suggestions?
 
Upvote 0
I'm not sure that I will have a better way but to consider that ..
  1. Are either, or both, of the tables sorted by Activation Code and then Date?
  2. If not, could they be sorted that way?
  3. Would a vba solution be acceptable?
 
Upvote 0
The tables are sorted by the Activation Date only currently, from oldest to newest. But, if you are asking me if they can be sorted based on Activation Code first (smallest to largest), and then by Activation Date (oldest to newest), then YES, I can sort them that way.

I am open to ANY solution that speeds up the calculation because once new data is entered into the tables, it basically freezes my sheet because it has to recalculate everything.

And I have both tables currently setup as ranges.
 
Upvote 0
Peter, thanks for the formula. My issue with the formula is that when it calculates, it freezes the program because the calculation time is significant. There are currently 120,000 rows of data, and the CPU usage goes to 100%, so how can I do this without it freezing, do you have any suggestions?
Using PowerQuery to "Merge" your matching results will be tonnes faster. The in-sheet methods get teadious over about 60K+. I've endured 500k lookup tables which helped push into PowerQuery, which is now known as the Get Data.
The PQ results can come out as a new Table, so you will have to adjust to that.
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

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