Trouble using index/match and xlookup

introspective

New Member
Joined
May 19, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello all - first time on here...
I am working with a set of data where I want to select the cost per month based on the product code and the quantity. Depending on the quantity, which sits between 2 numbers, determines the cost. I have tried using index, match and the xlookups and get part of the solution. How do I allocate the right cost depending on the quantity when it sits between the min and max values for each line item? Many thanks for your help on this.

ProductNameProductCodeCostPerMonthMinQuantityMaxQuantity
Product A
12345​
500.000​
1​
100​
Product A
12345​
600.000​
101​
151​
Product A
12345​
700.000​
152​
251​
Product A
12345​
900.000​
252​
751​
Product A
12345​
1000.000​
752​
1501​
Product A
12345​
1050.000​
1502​
3501​
Product A
12345​
2000.000​
3502​
7501​
Product A
12345​
0.400​
7502​
Product B
67890​
2500.000​
1​
100​
Product B
67890​
2600.000​
101​
151​
Product B
67890​
2900.000​
152​
251​
Product B
67890​
3100.000​
252​
751​
Product B
67890​
3200.000​
752​
1501​
Product B
67890​
4000.000​
1502​
3501​
Product B
67890​
5000.000​
3502​
7501​
Product B
67890​
1.500​
7502​
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How about
Fluff.xlsm
ABCDEFGHI
1ProductNameProductCodeCostPerMonthMinQuantityMaxQuantityProductQty
2Product A12345500110012345135600
3Product A12345600101151
4Product A12345700152251
5Product A12345900252751
6Product A1234510007521501
7Product A12345105015023501
8Product A12345200035027501
9Product A123450.47502
10Product B6789025001100
11Product B678902600101151
12Product B678902900152251
13Product B678903100252751
14Product B6789032007521501
15Product B67890400015023501
16Product B67890500035027501
17Product B678901.57502
Data
Cell Formulas
RangeFormula
I2I2=TAKE(FILTER(C2:C100,(B2:B100=G2)*(D2:D100<=H2)),-1)
 
Upvote 0
use an index/match but with a nearest clause
=INDEX($C$2:$C$24,MATCH(H3,IF($B$2:$B$24=G3,$D$2:$D$24),1))

lookup 2 criteria and 1 nearest.xlsx
ABCDEFGHI
1ProductNameProductCodeCostPerMonthMinQuantityMaxQuantity
2Product A12345500.0001100productcodeqtyprice
3Product A12345600.00010115112345112600.000
4Product A12345700.000152251
5Product A12345900.000252751
6Product A123451000.0007521501
7Product A123451050.00015023501
8Product A123452000.00035027501
9Product A123450.4007502
10Product B678902500.0001100
11Product B678902600.000101151
12Product B678902900.000152251
13Product B678903100.000252751
14Product B678903200.0007521501
15Product B678904000.00015023501
16Product B678905000.00035027501
17Product B678901.5007502
Sheet2
Cell Formulas
RangeFormula
I3I3=INDEX($C$2:$C$24,MATCH(H3,IF($B$2:$B$24=G3,$D$2:$D$24),1))


edit - reply as i posted
 
Upvote 0
use an index/match but with a nearest clause
=INDEX($C$2:$C$24,MATCH(H3,IF($B$2:$B$24=G3,$D$2:$D$24),1))

lookup 2 criteria and 1 nearest.xlsx
ABCDEFGHI
1ProductNameProductCodeCostPerMonthMinQuantityMaxQuantity
2Product A12345500.0001100productcodeqtyprice
3Product A12345600.00010115112345112600.000
4Product A12345700.000152251
5Product A12345900.000252751
6Product A123451000.0007521501
7Product A123451050.00015023501
8Product A123452000.00035027501
9Product A123450.4007502
10Product B678902500.0001100
11Product B678902600.000101151
12Product B678902900.000152251
13Product B678903100.000252751
14Product B678903200.0007521501
15Product B678904000.00015023501
16Product B678905000.00035027501
17Product B678901.5007502
Sheet2
Cell Formulas
RangeFormula
I3I3=INDEX($C$2:$C$24,MATCH(H3,IF($B$2:$B$24=G3,$D$2:$D$24),1))


edit - reply as i posted
Thank you etaf - this works. I couldn't figure out how to bring in the IF statement because I was thinking about it in a different way Many thanks for your help!
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHI
1ProductNameProductCodeCostPerMonthMinQuantityMaxQuantityProductQty
2Product A12345500110012345135600
3Product A12345600101151
4Product A12345700152251
5Product A12345900252751
6Product A1234510007521501
7Product A12345105015023501
8Product A12345200035027501
9Product A123450.47502
10Product B6789025001100
11Product B678902600101151
12Product B678902900152251
13Product B678903100252751
14Product B6789032007521501
15Product B67890400015023501
16Product B67890500035027501
17Product B678901.57502
Data
Cell Formulas
RangeFormula
I2I2=TAKE(FILTER(C2:C100,(B2:B100=G2)*(D2:D100<=H2)),-1)
Many thanks Fluff - I haven't used the TAKE or FILTER functions before, so will give them a go.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Similar threads

Forum statistics

Threads
1,217,365
Messages
6,136,124
Members
449,993
Latest member
Sphere2215

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