Find lowest value depending on conditions

Tybudd

Board Regular
Joined
Oct 13, 2009
Messages
60
Hey guys, I have a formula question.
This is the column setup for

Sheet Name=Prices
PRODUCT IDDESCRIPTIONEFFECTIVE FROM DATEPurchasing UoMPARTNER / VENDORPURCHASE PRICE



Product ID = List of Items by name
Description = Irrelevant
Effective Date = At what point the data comes into place.
Purchasing UoM = Irrelevant to the point
Partner/ Vender = Vendor that Supplies listed Product Product ID, and for what Price
Purchase Price = Price by way of Vendor, for said Product ID.


On another sheet I have:
Sheet Name=PRODUCTS
IDNAMEON INVENTORY SHEETSPARTNER / VENDOR


ID=same as Product type
Name = Description
ON INVENTORY SHEETS = Irrelevant
PARTNER / VENDOR = DESTINATION OF NEEDED FORMULA


Goal is to check on the Prices Page, checking according to "ID", and checking who has the lowest price, of there most current Effective Date.
So it would check all Partners that have the specific ID being looked for, then check the most current Effective date, then check who has the lowest price that meet those criteria, and return that value, or Vendor name.


Key Note for understanding, the Prices sheet is a running vertical log, recording each time an ID has a price change, by each vendor, and at what point (date), its effective.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
If you can add two more columns to your price sheet. One for the most current date for Vendor and one for their current price. Then maybe something like below.
I did add a column on your product sheet to show if more than 1 vendor had the same low price. Not knowing how you have things set up and what ver. of Excel you are using I didn't added an formulas to list the other vendors if there are any.
Also, you will need one of the later versions of Excel that has the functions MAXIFS and MINIFS (if not there are some changes that we can make).

In the example the formulas in D12 and F12 are array formulas that must be entered with CTRL-SHIFT-ENTER and then drag down as need for your products.

Book1
ABCDEFGH
1PRODUCT IDDESCRIPTIONEFFECTIVE FROM DATEPurchasing UoMPARTNER / VENDORPURCHASE PRICECurrent DateMin Price
217/5/2019Vendor120011/30/2019342
319/16/2019Vendor23429/16/2019342
428/12/2019Vendor23218/12/2019321
525/5/2019Vendor440610/30/2019320
6111/30/2019Vendor134211/30/2019342
7210/30/2019Vendor432010/30/2019320
8210/25/2019Vendor146210/25/2019462
9
10
11IDNAMEON INVENTORY SHEETSPARTNER / VENDORPriceMore than 1 Vendor
121Vendor1342Yes 
132Vendor4320 
Sheet1
Cell Formulas
RangeFormula
G2:G8G2=MAXIFS($C$2:$C$8,$A$2:$A$8,$A2,$E$2:$E$8,$E2)
H2:H8H2=MINIFS($F$2:$F$8,$A$2:$A$8,$A2,$C$2:$C$8,$G$2:$G$8)
D12, D13D12{=INDEX($E$2:$E$8,SMALL(IF(MIN(IF($A$2:$A$8=$A12,$H$2:$H$8))=$H$2:$H$8,ROW($H$2:$H$8)-ROW($H$2)+1),1))}
E12, E13E12=MINIFS($H$2:$H$8,$A$2:$A$8,$A12)
F12, F13F12{=IF(SUM(IF(FREQUENCY(IF($A$2:$A$8=$A12,IF($H$2:$H$8=$E12,MATCH($E$2:$E$8&"\"&$H$2:$H$8,$E$2:$E$8&"\"&$H$2:$H$8,0))),ROW($E$2:$E$8)-ROW($E$2)),1))>1,"Yes","")}
G12G12{=IFERROR(INDEX($C$2:$F$8,SMALL(IF(FREQUENCY(MATCH($E$2:$E$8,$E$2:$E$8,0),ROW($E$2:$E$8)-ROW($E$2)+1),ROW($E$2:$E$8)-ROW($E$2)+1),COLUMNS($C$15:G15)),MATCH($B27,$C$1:$F$1,0)),"")}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Check if the following is what you need.
Is an array formula:

Book1
ABCDEF
1PRODUCT IDDESCRIPTIONEFFECTIVE FROM DATEPurchasing UoMPARTNER / VENDORPURCHASE PRICE
212315/06/2019Ven149
312316/06/2019Ven249
412316/06/2019Ven351
524620/09/2019ven7101
624621/09/2019ven880
724622/09/2019ven980
824623/09/2019ven1081
9
10
11IDNAMEON INVENTORY SHEETSPARTNER / VENDORLOWEST PRICE
12123Ven249
13246ven980
Hoja13
Cell Formulas
RangeFormula
D12:D13D12{=LOOKUP(2,1/(($A$2:$A$8=$A12)*($F$2:$F$8=MIN(IF($A$2:$A$8=$A12,$F$2:$F$8)))*($C$2:$C$8)),$E$2:$E$8)}
E12:E13E12{=LOOKUP(2,1/(($A$2:$A$8=$A12)*($F$2:$F$8=MIN(IF($A$2:$A$8=$A12,$F$2:$F$8)))*($C$2:$C$8)),$F$2:$F$8)}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Dante - Not sure if your formulas will work. It looks like the same vendor(s) (per OP) could show up multiply times under a product with different effective dates. So, would need to find the most current price for each vendor based on effective date and then the lowest price.
 
Upvote 0
Dante - Not sure if your formulas will work. It looks like the same vendor(s) (per OP) could show up multiply times under a product with different effective dates. So, would need to find the most current price for each vendor based on effective date and then the lowest price.

Hi @AhoyNC, thanks for the observation, but I think the formula brings only one vendor and only one price. That is the goal.

If there is a tie of vendor, dates and prices, we would need to know the tiebreaker criteria. Or that the OP requests that all matches be displayed.

Book1
ABCDEF
1PRODUCT IDDESCRIPTIONEFFECTIVE FROM DATEPurchasing UoMPARTNER / VENDORPURCHASE PRICE
212316/06/2019Ven149
312316/06/2019Ven249
412316/06/2019Ven349
524620/09/2019ven7101
624620/09/2019ven882
724620/09/2019ven980
824620/09/2019ven1081
9
10
11IDNAMEON INVENTORY SHEETSPARTNER / VENDORLOWEST PRICE
12123Ven349
13246ven980
Hoja13
Cell Formulas
RangeFormula
D12:D13D12{=LOOKUP(2,1/(($A$2:$A$8=$A12)*($F$2:$F$8=MIN(IF($A$2:$A$8=$A12,$F$2:$F$8)))*($C$2:$C$8)),$E$2:$E$8)}
E12:E13E12{=LOOKUP(2,1/(($A$2:$A$8=$A12)*($F$2:$F$8=MIN(IF($A$2:$A$8=$A12,$F$2:$F$8)))*($C$2:$C$8)),$F$2:$F$8)}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


If you have an example where the formula does not work, I would greatly appreciate it if you can share it with me.
 
Upvote 0
See below. Vendor1 has two effect dates. Your formula pulls the lowest price, but not the most current date. OP states that the vendor may show up multiply times with different effective dates for same product. Sounds like the price sheet is a history of vendor pricing for product and they nee to check and find the most current price for each vendor and then the lowest.
Using your data below if we show vendor1 with different effective dates for product 123 it doesn't pick up the most current price for vendor1, just the lowest value.
Price should be 48 and not 46.
OP may need to clarify how price sheet is actual set up.

Book1
ABCDEF
1PRODUCT IDDESCRIPTIONEFFECTIVE FROM DATEPurchasing UoMPARTNER / VENDORPURCHASE PRICE
21236/16/2019Ven146
31236/16/2019Ven249
412310/30/2019Ven148
52469/20/2019ven7101
62469/20/2019ven882
72469/20/2019ven980
82469/20/2019ven1081
9
10
11IDNAMEON INVENTORY SHEETSPARTNER / VENDORLOWEST PRICE
12123Ven146<==Should be 48
13246ven980
Sheet1
Cell Formulas
RangeFormula
D12:D13D12{=LOOKUP(2,1/(($A$2:$A$8=$A12)*($F$2:$F$8=MIN(IF($A$2:$A$8=$A12,$F$2:$F$8)))*($C$2:$C$8)),$E$2:$E$8)}
E12:E13E12{=LOOKUP(2,1/(($A$2:$A$8=$A12)*($F$2:$F$8=MIN(IF($A$2:$A$8=$A12,$F$2:$F$8)))*($C$2:$C$8)),$F$2:$F$8)}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Thanks Ahoy, for taking the time to review it, it seems to me that now the formula does work.
But there is the detail of a tie, same ID, same date, same price.
In this case the formula returns the data below the list.

Book1
ABCDEF
1PRODUCT IDDESCRIPTIONEFFECTIVE FROM DATEPurchasing UoMPARTNER / VENDORPURCHASE PRICE
212316/06/2019Ven140
312316/06/2019Ven249
412330/10/2019Ven145
512330/10/2019Ven147
612330/10/2019Ven345
712330/10/2019Ven347
824620/09/2019ven882
924620/09/2019ven980
1024620/09/2019ven1081
11
12
13IDNAMEON INVENTORY SHEETSPARTNER / VENDORLOWEST PRICE
14123Ven345
15246ven980
Hoja13
Cell Formulas
RangeFormula
D14:D15D14{=LOOKUP(2,1/(($A$2:$A$10=$A14)*($F$2:$F$10=MIN(IF($A$2:$A$10=$A14,IF($C$2:$C$10=MAX(IF($A$2:$A$10=$A14,$C$2:$C$10)),$F$2:$F$10))))),$E$2:$E$10)}
E14:E15E14{=LOOKUP(2,1/(($A$2:$A$10=$A14)*($F$2:$F$10=MIN(IF($A$2:$A$10=$A14,IF($C$2:$C$10=MAX(IF($A$2:$A$10=$A14,$C$2:$C$10)),$F$2:$F$10))))),$F$2:$F$10)}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Here is the link to my document, on the Products Tab, I attempted to follow Ahoy's example to be displayed on D4, and the example of DanteAmor on D5, but I couldn't get neither to work, what do you see that I did wrong?Master Inventory Doc
 
Upvote 0
This is the correct formula.

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

Book1
ABCD
3IDNAMEON INVENTORY SHEETSPARTNER / VENDOR
4BOX001Box 20 GreenBOX001Stellar Snacks
PRODUCTS
Cell Formulas
RangeFormula
D4D4{=LOOKUP(2,1/((T_PRI[PRODUCT ID]=T_PR[[#This Row],[ID]])*(T_PRI[PURCHASE PRICE]=MIN(IF(T_PRI[PRODUCT ID]=T_PR[[#This Row],[ID]],IF(T_PRI[EFFECTIVE FROM DATE]=MAX(IF(T_PRI[PRODUCT ID]=T_PR[[#This Row],[ID]],T_PRI[EFFECTIVE FROM DATE])),T_PRI[PURCHASE PRICE]))))),T_PRI[PARTNER / VENDOR])}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


Your file with formula:
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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