XLookup using a calculated Array

BaconMcSandwich

New Member
Joined
Jun 14, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I have an xlooup function I want to use however the lookup and return array's will chage. It might be that I want the lookup array to be A:A and the return array B:B. OR I want the lookup to be C:C and the return D:D.

I can calculate the columns I want to use (Either the alphabetic or numeric values) but is there a way to get my Xlookup to use the values I've calculated?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
MrExcelPlayground2.xlsm
LMN
1412
15A16
16B27
17C38
18D49
19E510
20
21C8
222
Sheet35
Cell Formulas
RangeFormula
M21M21=XLOOKUP(L21,L15:L19,OFFSET(M15:M19,,L22-1,5,1),"",0)
 
Upvote 0
Hi,

Sort off, I think Offset might give me the return array, however for the lookup array you have still specified a value. If your table was repeated in the next 3 columns it might be that I want to lookup column L, or it might be that I want to lookup column O.

I can calculate the column I want to use, it's how to feed that into xlookup.
 
Upvote 0
Did you consider Choose it could select formula 1 or formula 2
 
Upvote 0
Maybe:

Book1
ABCDEFG
1AnimalsBugsCarsAgeWeightHeight
2AardvarkAntAlero1102
3BearBugBugatti2203
4CatCentipedeCamaro3305
5DogDragonflyDodge4407
6ElephantEarwigElectric55011
7
8
9LookupResult columnValueResult
10CarsHeightDodge7
Sheet10
Cell Formulas
RangeFormula
D10D10=XLOOKUP(C10,INDEX(A2:C6,0,MATCH(A10,A1:C1,0)),INDEX(E2:G6,0,MATCH(B10,E1:G1,0)),"Not found",0)
 
Upvote 0
Ultimately there could be 50+ different and search/return array pairs. Hence the reason I need to pick out the columns I need.

In my actual spreadsheet these tables are on seperate sheets, I've just put them together for ease.
Every week we will add new pair of ID's and finance rentals. I've calculated the week something was ordered based on the order date. But for that ID, in that Week I need to know the rate it was ordered at.
I will then be comparing the price it was ordered at to the latest week. Obviously the column that is the "latest" week will change also.

I've calculated that, for example week commencing is 7/6/21 is column C (lookup array) and that column D is the return array but it's just text values. I need to get XLookup to use it.

DataAnalysis.xlsx
ABCDEFGHIJK
131/05/2021Price07/06/2021PriceIDOrder DateWeekOrderedOrderRate
2ID1379ID1500ID101/06/202131/05/2021
3ID2448ID3200ID310/06/202107/06/2021
4ID3478ID4478ID505/06/202131/05/2021
5ID4428ID5428ID913/06/202107/06/2021
6ID5428ID9436
Sheet1
Cell Formulas
RangeFormula
J2:J5J2=I2-(WEEKDAY(I2,2)-1)
 
Upvote 0
If your tables are on different sheets, then let's design the formulas that way, since it'll make a BIG difference in how they are created. How are your sheets named? Do they have a consistent format, like "31052021", "07062021", etc.? Are the tables in the same place on every sheet? Columns A:B for example? How many rows per table (more or less)?
 
Upvote 0
I was intending 2 sheets. One with the main block of raw data (called "Data") where each week I add two new columns with that weeks ID's and their prices, last weeks wouund go in C and D, this weeks in columns E and F. The second sheet with the actual analysis comparing the rate when an item was ordered to the current week (called Orders).
The full list of ID and prices is about 50K rows.

Storing the weekly data in seperate sheets would make things easier in terms of the fact that I'd only be looking at columns A and B, however I'd need to reference a specific worksheet so I think it's the same problem just with the sheet name rather than the column's

I also can't really create a master list of ID's are new ones are addedd and some drop off, hence the idea of just looking at the speccific weeks. (I can deal with the error handling for that fine)
 
Upvote 0
I was intending 2 sheets. One with the main block of raw data (called "Data") where each week I add two new columns with that weeks ID's and their prices, last weeks wouund go in C and D, this weeks in columns E and F. The second sheet with the actual analysis comparing the rate when an item was ordered to the current week (called Orders).
The full list of ID and prices is about 50K rows.

Storing the weekly data in seperate sheets would make things easier in terms of the fact that I'd only be looking at columns A and B, however I'd need to reference a specific worksheet so I think it's the same problem just with the sheet name rather than the column's

I also can't really create a master list of ID's are new ones are addedd and some drop off, hence the idea of just looking at the speccific weeks. (I can deal with the error handling for that fine)
So for ID1 the order rate would be 379. Currently I would need to compare it to the latest data (In column's C and D) and compare that price to the value of 500. However when I add this weeks data (for 14/6/21) the rate for ID1 may have changed and to (for example) £450 so I'm now comparing
Whilst ID3 is in both sets of data based on it's order date it should return the data from columns C and D, so 200
 
Upvote 0
2 sheets is actually better than many. Let's say your data sheet looks like this:

Book1 (version 1).xlsb
ABCDEF
131/05/2021Price07/06/2021Price14/06/2021Price
2ID1379ID1500ID5111
3ID2448ID3200ID4222
4ID3478ID4478ID3333
5ID4428ID5428ID2444
6ID5428ID9436ID1555
Data


Just add your 2 new columns for new data.

Then you can use these formulas in your Orders sheet:

Book1 (version 1).xlsb
ABCDE
1IDOrder DateWeekOrderedOrderRate6/14/2021
2ID101/06/202131/05/2021379555
3ID310/06/202107/06/2021200333
4ID505/06/202131/05/2021428111
5ID913/06/202107/06/2021436Not found
Orders
Cell Formulas
RangeFormula
E1E1=TODAY()-(WEEKDAY(TODAY(),2)-1)
C2:C5C2=B2-(WEEKDAY(B2,2)-1)
D2:D5D2=XLOOKUP(A2,INDEX(Data!$A:$ZZ,0,MATCH(C2,Data!$A$1:$ZZ$1,0)),INDEX(Data!$A:$ZZ,0,MATCH(C2,Data!$A$1:$ZZ$1,0)+1),"Not found",0)
E2:E5E2=XLOOKUP(A2,INDEX(Data!$A:$ZZ,0,MATCH(E$1,Data!$A$1:$ZZ$1,0)),INDEX(Data!$A:$ZZ,0,MATCH(E$1,Data!$A$1:$ZZ$1,0)+1),"Not found",0)


In E1 I calculate the most recent date I'd expect in the Data tab, the the E formulas simply use that value instead of the C value.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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