if higher number within a given set of matching criteria is found, calculate new value based on highest, and or second highest

scottlarock

Board Regular
Joined
Apr 10, 2009
Messages
102
Hello,

I have been trying to get an answer to this, I'll try again.

I have 3 product types in column F, "level 1", "level 2", "level 3".
If, there is more than one product type sharing the same country (C) and Cust type (B), and "level 1" price is higher than either "level 2" or "level 3",

--> then "level 1" price should be 2% less than "level 2" (if there is such a product sharing the same country & cust type), and 4% less than "level 3" (if there is such a product sharing the same country & cust type).

Similarly, if there is a "level 2" with a higher price than a "level 3" within the same country (C) & cust type (B),

--> then "level 2" price should be 2% less than "level 3".

In this example, Z24 should be 4% less than Z26.

Any clue what the perfect formula would look like ? :°)

A
B
C
F
X
Y
Z
1
Region
Cust Type
Country
Product
Price
Quantity
Hypothetical D Price
24
Reg 1
Hosp
Cntry 1
level 1
920
88
1,058.2
25
Reg 1
Hosp
Cntry 1
level 2
2
26
Reg 1
Hosp
Cntry 1
level 3
1,106
0
1,005.5

<TBODY>
</TBODY>


Tons of thanks in advance,
Scott
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Small amendment to make things clearer, when I refer to prices, I mean Hypothetical prices.

Hello,

I have been trying to get an answer to this, I'll try again.

I have 3 product types in column F, "level 1", "level 2", "level 3".
If, there is more than one product type sharing the same country (C) and Cust type (B), and "level 1" hypothetical price (Z) is higher than either "level 2" or "level 3" hypothetical prices (Z),

--> then "level 1" hypothetical price (Z) should be 2% less than "level 2" hypothetical price (Z) (if there is such a product sharing the same country & cust type), and 4% less than "level 3" hypothetical price (Z) (if there is such a product sharing the same country & cust type).

Similarly, if there is a "level 2" with a higher hypothetical price (Z) than a potential "level 3" hypothetical price (Z) within the same country (C) & cust type (B),

--> then "level 2" hypothetical price (Z) price should be 2% less than "level 3" hypothetical price (Z).

In this example, Z24 should be 4% less than Z26.

Any clue what the perfect formula would look like ? :°)
ABCFXYZ
1RegionCust TypeCountryProductPriceQuantityHypothetical D Price
24Reg 1HospCntry 1level 1920881,058.2
25Reg 1HospCntry 1level 22
26Reg 1HospCntry 1level 31,10601,005.5

<TBODY>
</TBODY>
 
Upvote 0
Your sample data doesn't match your description - Level 1 price is not ​higher than Level 3 price.
 
Upvote 0
What result would you want if both conditions are true, i.e Level 2 price and Level 3 price are both higher than Level 1?
 
Upvote 0
Hi neil,
Yep... Hence the amendment in my auto reply above.
The column of focus is "hypothetical d price" in column z.

Have any suggestions ?
Thanks,
Scott
 
Upvote 0
What result would you want if both conditions are true, i.e Level 2 price and Level 3 price are both higher than Level 1?

Neil,

Thank you so much for takin a look at this dilemna.

First off, all three product types (level 1, level 2, level 3) are not systematically there. the formula should apply in the instances that there is more than one product type within the same country & cust type) where the lower levels have a higher hypothetical price.

In any case, I have two answers for you.

Number 1 :
If either condition is true, i.e : either "level 2" hypothetical price (should there be one in the given country & cust type) and or "level 3" hypothetical price (should there be one matching the country and cust type) are higher than "level 1" hypothetical price,
--> then " ".

Number 2 :
If either condition is true, i.e : either "level 2" hypothetical price and or "level 3" hypothetical price are higher than "level 1" hypothetical price,
--> then "level 1" hypothetical price should be 2% lower than "level 2" hypothetical price (should there be one matching the country and cust type), which in turn should be 2% lower than "level 3" hypothetical price (should there be one matching the country and cust type).

Tough to explain...but to make it simple... level 1 is supposed to be cheaper than level 2 which in turn is supposed to be cheaper than level 3.

Hope you can help me out !
scott
 
Upvote 0
This should give you the desired result for Levels 1 and 2, but you haven't said how you would arrive at the Level 3 hypothetical price...

=IF(Y2,MAX(SUMPRODUCT(--(C$3:C4=C2),--(RIGHT(F$3:F4)-1=RIGHT(F2)+0),(Z$3:Z4))*98%,SUMPRODUCT(--(C$3:C4=C2),--(RIGHT(F$3:F4)-2=RIGHT(F2)+0),(Z$3:Z4))*96%),0)
 
Upvote 0
This should give you the desired result for Levels 1 and 2, but you haven't said how you would arrive at the Level 3 hypothetical price...

=IF(Y2,MAX(SUMPRODUCT(--(C$3:C4=C2),--(RIGHT(F$3:F4)-1=RIGHT(F2)+0),(Z$3:Z4))*98%,SUMPRODUCT(--(C$3:C4=C2),--(RIGHT(F$3:F4)-2=RIGHT(F2)+0),(Z$3:Z4))*96%),0)

Hi Neil,

I haven't tried the formula just yet but it looks like it will do the trick.
From reading your reply, I realized that the data set looked confusing. I saw you were using column Y (quantity) from my initial table above, which I am not at all concerned with at this point....I would only like to tweak the hypothetical prices (this time around in column D to make it simple).
I will try to explain again real quick. I already have a formula calculating the hypothetical price based on the original price with a few conditions (nothing fancy), but the prices need fine tuning.
As you understood it, "level 1" hypothetical price should be 2% less than "level 2" hypothetical price, or 4% less than "level 3" hypothetical price (if there is such a product within the same country and same cust type)

Similarly, "level 2" hypothetical price should be 2% cheaper than "level 3" (if there is such a product within the same country and same cust type).
To answer your comment about "level 3", its hypothetical price will stay as it is, no need to tweak it.

Once I get the magic formula, which I think you pretty much sorted out already, I will try to incorporate it within the existing one, or work on another column.
I have pasted below only the data I need to be evaluated (no useless other columns like I had beforehand) :

I do apologize if I was unclear in anyway, and hope that you will be able to help me out.
A B C D
1Cust TypeCountryCodeHypothetical Price
2HospCountry 1Level 11,058.2
3HospCountry 1Level 2
4HospCountry 1Level 31,005.5

<COLGROUP><COL style="WIDTH: 83pt; mso-width-source: userset; mso-width-alt: 4059" width=111><COL style="WIDTH: 83pt; mso-width-source: userset; mso-width-alt: 4059" width=111><COL style="WIDTH: 65pt; mso-width-source: userset; mso-width-alt: 3145" width=86><COL style="WIDTH: 60pt; mso-width-source: userset; mso-width-alt: 2925" width=80><COL style="WIDTH: 97pt; mso-width-source: userset; mso-width-alt: 4717" width=129><TBODY>
</TBODY>


Tons of thanks,
Scott
 
Upvote 0
By the way, the right function won't work as the products have actual names, they are not actually called level 1,2,3.
Thx,
Scott
 
Upvote 0
Using the latest layout you posted (columns A:D), and taking account of Product names without numbers, give this a go in column E. You'll need to change the product names I've hard-coded into the array, or enter them into a separate area of your sheet and link to them...

=IF(D2,MAX(SUMPRODUCT(--(B$3:B4=B2),--(MATCH(C3:C4,{"Level 1","Level 2","Level 3"},0)-1=MATCH(C3:C4,{"Level 1","Level 2","Level 3"},0)),(D$3:D4))*98%,SUMPRODUCT(--(B$3:B4=B2),MATCH(C3:C4,{"Level 1","Level 2","Level 3"},0)=MATCH(C3:C4,{"Level 1","Level 2","Level 3"},0)),(D$3:D4))*96%,0)
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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