Vlookup with multiple conditions

olivera87

New Member
Joined
May 21, 2022
Messages
6
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2011
  5. 2010
Platform
  1. Windows
Hello,

I ask for your help. I would like to optimize my everyday work, since now it is devided into many excel files that take long to check them all. I have joined all the excel files into one, and now I need help to set up an automatic output cell that would agree with many conditions.

So we have columns: CUSTOMER CODE (3-5 numbers usually), PRODUCT CODE (also 3-5 numbers usually), QUANTITY, PRICE, DATE. There are many customers that have some of the same products, with a price (unique for every partner) that depends on the order quantity (the more products you order, the lower the price). Example: customer 12546 has a product 5555 for a price 2,10 eur if they order 100 pcs, 2,00 eur for 200 pcs, and 1,6 eur for 500 pcs). The quantity is unique for every partner, just like the prices. The date is important since the price can change in the future and I would like to only enter a new period and price when it does.

My wish is to have a sheet with a table where I would write: CUSTOMER CODE, PRODUCT CODE, QUANTITY AND DATE manualy and the PRICE per pcs would be shown automaticly in the next cell considering the conditions. I attached the picture of how the data base would look, and what I would like to get out with a formula.

Please help me, which function would be the best. As I researched, VLOOK would not be the best for this.

Thank you so much for your help. :)
 

Attachments

  • excel example.PNG
    excel example.PNG
    21.3 KB · Views: 20

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Welcome to Mr. Excel,

It would help greatly if you show your sample using XL2BB so that retyping your data isn't required on the part of someone helping you.

Using 365, does this do it in M3?

Code:
=FILTER(F3:F13,(J3=B3:B13)*(K3=C3:C13)*(L3>=D3:D13)*(L3<=E3:E13))

Book5
BCDEFGHIJKLM
2PartnerproductfromtopricePartnerProductQPrice
368131532612003.216813153263501.22
46813153262013002.13
56813153263014001.22
668131532640199999991.1
768131112312001.84
86813111232013001.63
96813111233014001.22
1068131112340199999991.05
1168131112340199999990.95
124238251611001.23
134238251610199999991.01
Sheet1
Cell Formulas
RangeFormula
M3M3=FILTER(F3:F13,(J3=B3:B13)*(K3=C3:C13)*(L3>=D3:D13)*(L3<=E3:E13))
 
Upvote 0
Welcome to the MrExcel board!

My wish is to have a sheet with a table where I would write: CUSTOMER CODE, PRODUCT CODE, QUANTITY AND DATE manualy and the PRICE per pcs would be shown automaticly in the next cell considering the conditions. I attached the picture of how the data base would look, and what I would like to get out with a formula.
Seems like Date is missing from your results section. If that is to be included then you would need to add a further two bracketed sections to the formula suggested above to account for the date.
Alternatively, if you want the formula to work in all your Excel versions, you could try this. It assumes that only a single row of the original data would meet all the conditions given.

22 05 22.xlsm
ABCDEFGHIJKLMN
1
2PartnerProductq fromq topricedate fromdate toPARTNERPRODUCTQDATEPRICE
368131532612003.211/01/202231/12/999968131532635021/01/20221.22
46813153262013002.131/01/202231/12/999968131112341023/04/20220.95
56813153263014001.221/01/202231/12/9999423825161002/02/20221.23
668131532640199999991.11/01/202231/12/9999
768131112312001.841/01/202231/12/9999
86813111232013001.631/01/202231/12/9999
96813111233014001.221/01/202231/12/9999
1068131112340199999991.051/01/202231/03/2022
1168131112340199999990.951/04/202231/12/9999
124238251611001.231/01/202231/12/9999
134238251610199999991.011/01/202231/12/9999
14
Lookup Price
Cell Formulas
RangeFormula
N3:N5N3=SUMIFS(F$3:F$13,B$3:B$13,J3,C$3:C$13,K3,D$3:D$13,"<="&L3,E$3:E$13,">="&L3,G$3:G$13,"<="&M3,H$3:H$13,">="&M3)
 
Upvote 0
Thank you all for your help. I entered this formulas and I did not show me the result, it wrote an error. I copied it into the cell and it didn't work. Was I supposed to change something? Sorry if I am asking very basic questions, but I am new to this.

I put a little more thinking into it and it would be great if the part where you put un inquery like partner, article, q and date would be in a seperate sheet (worksheet 2 in same file), so I could use it to import in our program.

Is this possible?

Thank you. :)
 
Upvote 0
Update, the formula =SUMIFS(F$3:F$13,B$3:B$13,J3,C$3:C$13,K3,D$3:D$13,"<="&L3,E$3:E$13,">="&L3,G$3:G$13,"<="&M3,H$3:H$13,">="&M3) works great! :) Thank you so much :)

Now my only wish is, that it could be moved to another sheet. :) Any ideas?
 
Upvote 0
Can't you just change the references based on the other sheet?

Something like:

Code:
=SUMIFS(Sheet1!F$3:F$13,Sheet1!$B$3:$B$13,B3,Sheet1!C$3:C$13,C3,Sheet1!D$3:D$13,"<="&D3,Sheet1!E$3:E$13,">="&D3,Sheet1!G$3:G$13,"<="&E3,Sheet1!H$3:H$13,">="&E3)

With this formula in F3 and filled down and the data in B3:F5
 
Upvote 0
Can't you just change the references based on the other sheet?

Something like:

Code:
=SUMIFS(Sheet1!F$3:F$13,Sheet1!$B$3:$B$13,B3,Sheet1!C$3:C$13,C3,Sheet1!D$3:D$13,"<="&D3,Sheet1!E$3:E$13,">="&D3,Sheet1!G$3:G$13,"<="&E3,Sheet1!H$3:H$13,">="&E3)

With this formula in F3 and filled down and the data in B3:F5
Thank you so much, works perfectly! :)
 
Upvote 0
Welcome to Mr. Excel,

It would help greatly if you show your sample using XL2BB so that retyping your data isn't required on the part of someone helping you.

Using 365, does this do it in M3?

Code:
=FILTER(F3:F13,(J3=B3:B13)*(K3=C3:C13)*(L3>=D3:D13)*(L3<=E3:E13))

Book5
BCDEFGHIJKLM
2PartnerproductfromtopricePartnerProductQPrice
368131532612003.216813153263501.22
46813153262013002.13
56813153263014001.22
668131532640199999991.1
768131112312001.84
86813111232013001.63
96813111233014001.22
1068131112340199999991.05
1168131112340199999990.95
124238251611001.23
134238251610199999991.01
Sheet1
Cell Formulas
RangeFormula
M3M3=FILTER(F3:F13,(J3=B3:B13)*(K3=C3:C13)*(L3>=D3:D13)*(L3<=E3:E13))

Hello,

can you please help me add a condition of date into the code.
Thank you.
 
Upvote 0
Glad to help.
Update, it works great but there is a problem, that when you enter a product with two different prices to mach both conditions, it sums them together.

To explain in example: partner 423, product 4152, q 100-200, price 1,50 and another entry: partner 423, product 4152, q 200-1000 price 1,52 the result will be price 3,02 for q (for example) 200.

Is it possible to use a different code, that would like select a smaller price in this case?

I fully understand the base file (all the data) has to be cleared and that the duplicat values are not allowed, but at the volume of product we have in our base it can happen quickly.

I hope you understand what I wrote.

Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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