Exclude a cell in MIN function, which is embedded in a XLOOKUP function

vttrian

New Member
Joined
Feb 24, 2023
Messages
7
Office Version
  1. 2021
Platform
  1. Windows
Say that I have products in column A (A1:A12) and prices in column B (B1:B12). I use the MIN and the XLOOKUP functions to see the most cheap product.

This is done with =XLOOKUP(MIN(B1:B12);B1:B12;A1:A12)

Let's say the function above returns A3 as the cheapest product.

In case the lowest price corresponds to 2 or 3 products though, the function will ignore them and return only the first one. (A3 product's price is 3$, but also A5 product's price is 3$).

Is there a way to run the MIN function again, in another cell, excluding the price (and therefore the product) that returned in the first run, by excluding the cell of column B from the range?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi *vttrian,

You could try using the FILTER function. I believe it would be "=FILTER(A1:A12,B1:B12=MIN(B1:B12))".

I hope that helps,

Doug
 
Upvote 0
Hi *vttrian,

You could try using the FILTER function. I believe it would be "=FILTER(A1:A12,B1:B12=MIN(B1:B12))".

I hope that helps,

Doug
Thank you very much duggie33! That almost does the trick. I actually need the names of the 3 products with the lowest prices. They may all 3 have the same price, or the 2 of them, or none of them. Your proposal brought me closer to the solution but it returns the products with the single lowest price. So I changed the MIN function to SMALL. The results were the same. Do you have any other suggestions?
 
Upvote 0
Maybe something like this:
Book1
ABCDE
1ProductPriceProductPrice
2Prod112Prod45
3Prod211Prod65
4Prod39Prod76
5Prod45
6Prod512
7Prod65
8Prod76
9Prod813
10Prod916
11Prod109
12Prod1112
Sheet2
Cell Formulas
RangeFormula
D2:E4D2=FILTER($A$2:$B$12,($B$2:$B$12<=SMALL($B$2:$B$12,3)))
Dynamic array formulas.
 
Upvote 1
Welcome to the MrExcel board!

What do you want to happen if the 4th lowest price is the same as the 3rd lowest etc? See my sample data below.
Perhaps you want all the 'equal' products listed like @AhoyNC's formula would (though I have added a SORT so they are in order from lowest), otherwise if you definitely only want 3 listed I have given 2 options depending on whether you have all the latest functions or not.

23 02 25.xlsm
ABCDEFGHIJK
1ProductPriceProductPriceProductPriceProductPrice
2Prod16Prod45Prod45Prod45
3Prod211Prod65Prod65Prod65
4Prod39Prod16Prod16Prod16
5Prod45Prod76
6Prod512Prod86
7Prod65
8Prod76
9Prod86
10Prod916
11Prod109
12Prod1112
3 Lowest
Cell Formulas
RangeFormula
D2:E6D2=SORT(FILTER(A2:B12,(B2:B12<=SMALL(B2:B12,3))),2)
G2:H4G2=TAKE(SORT(A2:B12,2),3)
J2:K4J2=INDEX(SORT(A2:B12,2),{1;2;3},{1,2})
Dynamic array formulas.
 
Upvote 1
Maybe something like this:
Cell Formulas
RangeFormula
D2:E4D2=FILTER($A$2:$B$12,($B$2:$B$12<=SMALL($B$2:$B$12,3)))
Dynamic array formulas.
Yup! That did it. Thank you very much. I really appreciate this. (I love this community!!!)
 
Upvote 0
Welcome to the MrExcel board!

What do you want to happen if the 4th lowest price is the same as the 3rd lowest etc? See my sample data below.
Perhaps you want all the 'equal' products listed like @AhoyNC's formula would (though I have added a SORT so they are in order from lowest), otherwise if you definitely only want 3 listed I have given 2 options depending on whether you have all the latest functions or not.

Cell Formulas
RangeFormula
D2:E6D2=SORT(FILTER(A2:B12,(B2:B12<=SMALL(B2:B12,3))),2)
G2:H4G2=TAKE(SORT(A2:B12,2),3)
J2:K4J2=INDEX(SORT(A2:B12,2),{1;2;3},{1,2})
Dynamic array formulas.
This works too. The first and last option at least. I am currently interested in the third option, so my problem is solved. The second option didn't work for me (I must be missing the function). Once again... I can't thank you enough guys!!
 
Upvote 0
Upvote 0
Hello guys.

The 3rd option mentioned above works like a charm. But unfortunately now I need to run this function every once in a while. I can manage to insert a button to run a sub in vba. Can the sort/index functions work in vba as a sub?
 
Upvote 0
Is this what you mean?

VBA Code:
Sub Low3()
  With Range("A2", Range("B" & Rows.Count).End(xlUp))
    .Offset(-1, 3).Resize(1).Value = .Rows(0).Value
    .Offset(0, 3).Cells(1, 1).Formula2 = "=INDEX(SORT(" & .Address & ",2),{1;2;3},{1,2})"
    With .Offset(, 3).CurrentRegion
      .Select
      .Value = .Value
      .Columns.AutoFit
    End With
  End With
End Sub

Before:

vttrian.xlsm
ABCDEF
1ProductPrice
2Prod16
3Prod211
4Prod39
5Prod45
6Prod512
7Prod65
8Prod76
9Prod86
10Prod916
11Prod109
12Prod1112
Sheet1


After:

vttrian.xlsm
ABCDEF
1ProductPriceProductPrice
2Prod16Prod45
3Prod211Prod65
4Prod39Prod16
5Prod45
6Prod512
7Prod65
8Prod76
9Prod86
10Prod916
11Prod109
12Prod1112
Sheet1
 
Upvote 1

Forum statistics

Threads
1,215,573
Messages
6,125,608
Members
449,238
Latest member
wcbyers

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