Index Match / Xlookup modes for less than except...

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
439
Office Version
  1. 365
Platform
  1. Windows
Hi

I'm trying a matrix 2 way lookup where the the columns are for prices based on volume thresholds

I've ben trying to find 1 formula that will work with one set of threshold numbers (D6:H6 in the example below), but I can't seem to geteither Index & Match or Xlookup to do it with one of the match types that works for numbers above or below the smallest or largest volume number

Book1
BCDEFGHIJ
6Prices for volumes up to:1001,00010,00050,000100,000
7TestPrice 1Price 2Price 3Price 4Price 5
8Cant sortTest 10.050.0480.030.020.011
9this list->Test 20.040.0290.0280.0210.01
10
11
12Lookup the price of:Test 2
13
14Price of 231 of Test 2 is:0.04<--Index & Match type 1 ("less than"): Not Correct
150.029<--Xlookup mode 1 ("exact match or next smaller") - Correct
16Price of 78 of Test 2 is:#N/A<--Index & Match type 1 ("less than") - Not found because there isn't a value in D2:DH smaller than 78
170.04<--Xlookup mode 1 ("exact match or next smaller") : Correct
18Price of 153,000 of Test 2 is:0.01<--Index & Match type 1 ("less than") - Correct
19#N/A<--Xlookup mode 1 ("exact match or next smaller") : Not found
Sheet2
Cell Formulas
RangeFormula
D14D14=INDEX(Table4[[Price 1]:[Price 5]],MATCH(D12,Table4[Test],0),MATCH(231,D6:H6,1))
D15D15=XLOOKUP(231,D6:H6,XLOOKUP(D12,Table4[Test],Table4[[Price 1]:[Price 5]]),,1)
D16D16=INDEX(Table4[[Price 1]:[Price 5]],MATCH(D12,Table4[Test],0),MATCH(78,D6:H6,1))
D17D17=XLOOKUP(78,D6:H6,XLOOKUP(D12,Table4[Test],Table4[[Price 1]:[Price 5]]),,1)
D18D18=INDEX(Table4[[Price 1]:[Price 5]],MATCH(D12,Table4[Test],0),MATCH(153000,D6:H6,1))
D19D19=XLOOKUP(153000,D6:H6,XLOOKUP(D12,Table4[Test],Table4[[Price 1]:[Price 5]]),,1)


What formula would work for all permutations?
 
Ahh, I guess I'd need to put real values in it which are the same as for the previous column
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
No you don't, if anything over 50k units you be sold at the 100k price, just make the change I suggested.
 
Upvote 0
Yes you're right.

However, in my scenario the volume thresholds are the published volume discounts of various suppliers which would cause a bit of confusion if I changed them. In theory it shouldn't be possible to order more than the largest volume listed, but in practice it happens so I need to be able to return a price rather than an error.

So for completeness, I found a way to do with a formula, without an extra column or changing the thresholds by setting the [match_mode] of the XLOOKUP to 1, and then exploiting the [not_found] option in XLOOKUP to repeat the formula but this time with the [match_mode] set to -1

ie: =XLOOKUP (lookup, lookup_array, return_array,XLOOKUP (lookup, lookup_array, return_array, , -1), 1)



Book1.xlsx
CDEFGHI
24Prices for volumes up to:1001,00010,00050,000100,000
25TestPrice 1Price 2Price 3Price 4Price 5
26Test 10.050.0480.030.020.011
27Test 20.040.0290.0280.0210.01
28
29At volumes of:659938,95648,00058,000120,000
30the price of Test 2 is:0.040.0290.0280.0210.010.01
Sheet2
Cell Formulas
RangeFormula
D30D30=XLOOKUP(D29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]), XLOOKUP(D29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]),,-1),1)
E30E30=XLOOKUP(E29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]), XLOOKUP(E29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]),,-1),1)
F30F30=XLOOKUP(F29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]), XLOOKUP(F29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]),,-1),1)
G30G30=XLOOKUP(G29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]), XLOOKUP(G29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]),,-1),1)
H30H30=XLOOKUP(H29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]), XLOOKUP(H29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]),,-1),1)
I30I30=XLOOKUP(I29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]), XLOOKUP(I29,D24:H24, XLOOKUP("Test 2",Table43[Test],Table43[[Price 1]:[Price 5]]),,-1),1)
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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