Lookup based on calculation of multiple criteria

bujabuja

New Member
Joined
Feb 7, 2019
Messages
2
Hi,

I have a table that looks like this:

ItemClassStartEnd
Item1A5080
Item2A60150
Item3A120160
Item4A150250
Item5B300400
Item6B400500
Item7C50300
Item8C70150
Item9C150300

<tbody>
</tbody>


If my lookup looks like this:


ClassLocation
LookupA70

<tbody>
</tbody>


I am looking for a function that will give me the Item that meets the criteria Class=A, Location >= Start, Location <= End.

This can be achieved via =index($A$2:$A$10;small(if((A=$B$2:$B$10)*(Location>=$C$2:$C$10)*(Location<=$D$2:$D$10);Row($A$2:$A$10)-1;"");1))

However, if there are multiple matches for this formula I would like to order them with (Location-Start)*(End-Location) as criteria going from highest to lowest. If at all possible I would like to do this without extra columns added.

Thank you for your input.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to the Board.

It would help if you could give an example of your desired output. But here's one possibility:


ABCDEFGHIJ
1ItemClassStartEndClassLocation
2Item1A5080Item3A155
3Item2A60150Item4
4Item3A120160
5Item4A150250
6Item5B300400
7Item6B400500
8Item7C50300
9Item8C70150
10Item9C150300

<tbody>
</tbody>
Sheet10

Array Formulas
CellFormula
G2{=IFERROR(INDEX($A$2:$A$10,SMALL(IF($B$2:$B$10=$H$2,IF($C$2:$C$10<=$I$2,IF($D$2:$D$10>=
$I$2,IF(COUNTIF($G$1:$G1,$A$2:$A$10)=0,ROW($A$2:$A$10)-ROW($A$2)+1)
)
)
),1
)
),""
)}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
ABCDEFGHIJ
1ItemClassStartEndLookup
ClassLocation
2Item1A30
80A
70
3Item2A40
150
4Item3A60
160Output
5Item4A150250Item2
30
80
2400
6Item5B300400Item3
10
90
900
7Item6B400500Item1
40
10
400
8Item7C50300
9Item8C
70150
10Item9C150300

<tbody>
</tbody>




Hi Eric,

thank you very much for your reply. I changed the numbers slightly.

The desired output would be:
Item2
Item3
Item1

I added the calculations for clarification, but these should not appear in the final version. The output is ordered by (Location-Start)*(End-Location).

I looked at your formula. I see that you cascaded the if statement and you added the countif-function. I don't quite understand what the countif function does here. Please explain.

Thank You. :):)
 
Upvote 0
I think we're getting closer to your ultimate goal, but I'm a bit confused by your example. Item2 in the table on the left has Start and End of 40/150, but in the response table on the right it has 30/80?

But take a look at this:

ABCDEFGHIJK
1ItemClassStartEndLookupClassLocation
2Item1A3080A70
3Item2A40150
4Item3A60160Output
5Item4A150250Item3601609600
6Item5B300400Item2401506000
7Item6B400500Item130802400
8Item7C50300000
9Item8C70150
10Item9C150300

<tbody>
</tbody>
Sheet11

Worksheet Formulas
CellFormula
H5=SUMIFS(C$2:C$10,$A$2:$A$10,$G5,$B$2:$B$10,$H$2)
J5=H5*I5

<tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
G5{=IFERROR(INDEX($A$2:$A$10,MATCH(LARGE(IF(($B$2:$B$10=$H$2)*($C$2:$C$10<=$I$2)*($D$2:$D$10>=$I$2)*(COUNTIF($G$4:$G4,$A$2:$A$10)=0),$C$2:$C$10*$D$2:$D$10),1),IF(($B$2:$B10=$H$2)*($C$2:$C$10<=$I$2)*($D$2:$D$10>=$I$2)*(COUNTIF($G4:$G4,$A$2:$A$10)=0),$C$2:$C$10*$D$2:$D$10),0)),"")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



The main formula is in G5. The H and I formulas just return the matching locations, and J is just the product. You can remove any of those.

The formula mainly finds the matching rows, calculates C*D, and finds the largest. It then uses MATCH to find the location of the largest value within the matching rows again. The COUNTIF looks at the rows above the formula (so G5 looks at G4, G6 looks at G4:G5, G7 looks at G4:G6, etc.) to see if the item has already been found. If it has, it's excluded from further consideration, meaning that the next row down will find the next highest value, or the highest remaining after the highest is excluded.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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