Excel Commission Formula - excel

Wondering if I could get help getting the correct formula to figure out the comm% based off the price it was sold at.
Basically, there are two spreadsheets.
First one is our price grid to show what the commission pct will be:
Product - 20% - 15% - 10%
Widget 1 - 3990 - 3490 - 3090
Widget 2 - 4990 - 4490 - 4090
Widget 3 - 5990 - 5490 - 5090
The second spreadsheet would list the Products sold and at what price it was sold at:
Widget 2 - $4690
Widget 3 - $5100
Widget 1 - $4000
I was thinking INDEX/MATCH. I can do the MATCH correctly to find the correct row, but I'm not sure how to incorporate that price range lookup into the formula.
In the example I gave above the commission should be 15%, 10% & 20% respectively.
Need to create a formula that matches the Product and then takes the price sold at and matches it to what column it would fall under and give me the % for that column.
I've spent weeks search the net and I can only get half way there. The MATCH to figure out which row the Product is on is simple, it's the price matching that's got me stumped.
Thanks.

You can solve this by making use of the rarely used Hlookup function, using it's range_lookup option. The only requirement for it is that you reorder your commission data from low% to high%. like this:
Product 10% 15% 20%
Widget 1 3090 3490 3990
Widget 2 4090 4490 4990
Widget 3 5090 5490 5990
If you've done this, you can use this formula to get the correct commission
=OFFSET(Sheet1!$A$1;0;MATCH(HLOOKUP(INT(SUBSTITUTE(B1; "$"; ""));INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A ));1; TRUE);INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A)) )-1)
This is the breakdown:
Format input as integer (commission data is int, values are $)
SUBSTITUTE(B1; "$"; "")
Use the input to put together the reference row for the Hlookup. We use indirect to add the sheetname and ":" to the reference.
INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A ))
Use Hlookup to find the matching value:
HLOOKUP(INT(SUBSTITUTE(B1; "$"; ""));INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A ));1; TRUE)
Use the found value in a horizontal match function to find the used column, and substract 1:
MATCH(<hlookup>; INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A))) - 1
Use Offset to find the matching value
Offset(Sheet1!$A$1;0; <match>)

Related

How can I give discount to the highest priced product

enter image description hereI am trying to figure out how I can solve the following problem in Excel.
First "buis" with the highest "contract tarief" should cost 100% of the "contract tarief" price. The following highest "buis" should cost 50% of the "contract tarief price" all the other "buizen" will cost 25% of the mentioned "contract tarief" price.
For example 6 "buizen" in total 2 of 200mm 1 of 150mm 1 of 125mm and 2 of 100mm. Normally that would cost 8 + 3 + 2 ++ 2 = 15. But the first "highest price one" is 200mm that one will be 4 and the next 2 the rest will be 25% so 25% of 11. And that will be the total price.
So I am trying to make it automated that it automaticly finds the 2 highest costing "buizen" and calculate that they cost 1x100% and 1x50% and then totalling all of the rest "buizen" with the 25% cost.
I hope I make sense. I am from the Netherlands so please ask if you need more clarification. I appreciate your help.
I don't know the layout of your spreadsheet, but;
if column A is your price and B contains your 'contract tarief' then in cell C2 you could enter:
=IF($B2 = MAX($A:$A), $B2, IF(RANK($A2, $A:$A, 0)+COUNTIF($A:$A, $A2)-1 = 2, $B2*0.5, $B2*0.25))
You'll want to adapt that to match your layout of course.
Note that this will return the 100% tarief for all lines with the max value, the 50% for all lines with the second value, and the 25% for everything lower than that (things with duplicate values will get duplicate tariefs).
To give credit where it's due, I copied the unique ranking formula from here.
If one has Excel O365, you could try:
Formula in F2:
=LET(X,SORT(FILTER(A2:D6,D2:D6>0),1,-1),Y,SUM(INDEX(X,0,4)*(INDEX(X,0,3)/4)),Z,SUM(INDEX(X,0,4)),A,INDEX(X,1,4),Y+INDEX(X,1,3)*0.75+IF(Z=1,0,INDEX(X,IF(A>1,1,2),3)/4))
This is long and wordy and paining my head, I'm sure someone can come up with something clever =)
EDIT: The proper Dutch translation of this formula:
=LET(X;SORTEREN(FILTER(A2:D6;D2:D6>0);1;-1);Y;SOM(INDEX(X;0;4)*(INDEX(X;0;3)/4));Z;SOM(INDEX(X;0;4));A;INDEX(X;1;4);Y+INDEX(X;1;3)*0,75+ALS(Z=1;0;INDEX(X;ALS(A>1;1;2);3)/4))

Nested IF statements assistance

I made a small workbook that exactly mimics the original formulas I posted. The purpose of the workbook is to calculate the bonuses for each employee based on various inputted combinations (listed below). Here is how my workbook is laid out:
Data Tab
Bonus Tab
Base Bonus Tab
Summary Tab
Picture of the Data tab that I utilize to input the different combinations:
Data Tab
List of the combinations:
Employee % (cell B3) & Company % (cell B4) cells have numbers inputted = Combo 1 (range: 0%-100%)
Employee $ (cell B5) & Company $ (cell B6) cells have numbers inputted =Combo 2 (range: $0-no limit)
Base Salary (B2) is Yes & Employee % (cell B3) cells have been inputted = Combo 3 (Base Salary is either Yes or blank)
Base Salary (B2) is Yes & Job Title (A8) & Employee % (cell B8) cell have been inputted = Combo 5
I use cell C1 for an IF statement to dictate which formula to use based on the combinations above. (ex. numbers in B5 & B6 = 1)
=IF(AND($B$2<>"",$A$8<>"",$B$8<>""),5,IF(AND($B$2<>"",$B$3<>""),3,IF($B$3<>"",1,IF($B$5<>"",2))))
Picture of the Bonus Tab: Bonus Tab
Picture of the Base Bonus Tab: Base Bonus Tab
Picture of the Summary Tab: Summary Tab
I have created formulas for each combinations separately, but as soon as I try to combine them into one, I get the Too many arguments error message since combo 3 & combo 5 use false within the IF statement. I am attempting to avoid making a calculations table and would prefer utilizing one formula on the summary tab by employee in column B.
I will further explain combo 3 specifically - If the base bonus is less than the regular bonus, than multiply the base bonus * Employee % + Company&Vendor bonus * Company %. If base bonus is more than regular bonus, than multiply regular bonus * Employee % + Company&Vendor bonus * Company %.
Example:
Bobby
Base Bonus $50 < Regular Bonus $100
$50 * 50% employee % = $25
+ $200 company + $0 vendor * 50% company = $100
Final answer is $125 if base bonus if < regular bonus
I will further explain combo 5 specifically - If the base bonus is less than the regular bonus, than multiply the base bonus * employees job title Employee % + Company&Vendor bonus * job title Company %. If base bonus is more than regular bonus, than multiply regular bonus * employees job title Employee % + Company&Vendor bonus * job title Company %.
Example:
Bobby
Base Bonus $50 < Regular Bonus $100
Find Bobby's Job title to determine Employee % & Company %
75% Employee % for Officers and 50% Company %
75% * $50 + 50% * ($200 Company & $0 Vendor) = $137.5
Final answer is $137.5 of base bonus if < regular bonus
Here is list of each formula by combo:
Combo 1:
=IF(Data!$C$1=1,Data!$B$3*Bonus!D2+Data!$B$4*(Bonus!E2+Bonus!F2))
Combo 2:
=IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$6+Data!B5))
Combo 3:
=IF(Data!$C$1=3,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2),VLOOKUP(A2,Bonus!$A$2:$D$5,4,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2)))
Combo 5:
IF(Data!$C$1=5,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!E2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE),VLOOKUP(A2,Bonus!$A$2:$D$5,4,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!E2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE)))
Hopefully this is a lot more clear than my initial post and can easily be replicated. Let me know if you have any questions, Thank you!
I found some issues in your formulas
Combo3 In the else option you have A2 following the pattern it should be Summary!A2
Combo5 the sum is in the same cell you have (Bonus!E2+Bonus!E2) it should be (Bonus!E2+Bonus!F2)
I didn't record the initial nested If to compare why it is not working. I got this:
Final Nested:
=IF(Data!$C$1=1,Data!$B$3*Bonus!D2+Data!$B$4*(Bonus!E2+Bonus!F2),IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$6+Data!B5,IF(Data!$C$1=3,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2),VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2)),IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!F2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE),VLOOKUP(B2,Bonus!$A$2:$D$5,4,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!F2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE)))))

Excel: Formula to calculate the number of days occurring in multiple date ranges for different individuals

I am trying to develop an Excel formula that allows me to count the number of days occurring within two date ranges for different individuals. Here is a sample of my dataset:
id admDt sepDt admDur id dxDt-1 dxDt admDurTot
1 16/01/2000 18/01/2000 2 1 24/01/2000 24/02/2000 28
1 22/01/2000 18/02/2000 27 2 30/03/2000 30/04/2000 0
1 20/02/2000 22/02/2000 2 3 3/02/2000 3/03/2000 0
1 24/02/2000 28/02/2000 4 4 31/12/1999 31/01/2000 0
5 19/05/2000 20/06/2000 32 5 20/05/2000 20/06/2000 31
8 25/12/1999 28/12/1999 3 6 13/11/2000 13/12/2000 0
8 18/01/2000 26/01/2000 8 7 14/04/2000 14/05/2000 0
8 28/01/2000 28/01/2009 3288 8 23/12/1999 23/01/2000 9
9 9/02/2000 9/03/2000 0
For columns A-D, each row reflects an event (in this case, a hospital admission):
id = individual's ID number
admDt = date of admission
sepDt = date of discharge
admDur = duration (in days) of admission
Please note that multiple rows can relate to one individual (e.g., A2:E5).
For columns F-I, each row reflects one individual's data:
id = individual's ID number
dxDt-1 = date one month preceding diagnosis
dxDt = date of diagnosis
admDurTot = total duration (in days) of admission
Date ranges for each admission (admDt and sepDt) and individual (dxDt-1 and dxDt) can be different. While the date ranges for each event may span across months (e.g., cells A3:C3 or A9:C9), I am interested in calculating the number of days the person spent in hospital (admDurTot) in the month preceding their diagnosis (dxDt). Please note that the values in admDurTot reflect those I would like to obtain, rather than those obtained from different formulae I have used.
I have tried variations of the SUMIFS formula:
=SUMIFS($D:$D, $A:$A, $G2, $B:$B, ">=" & $H2, $C:$C, "<=" & $I2)
=SUMIFS($D:$D, $A:$A, $G2, $B:$B, "<=" & $I2, $C:$C, ">=" & $H2)
=SUMIFS($D:$D, $A:$A, $G2, $B:$B, ">=" & $H2, $C:$C, ">" & $H2, $C:$C, "<=" & $I2)
however, they are confounded by the fact that both admDt and sepDt often fall outside the range of interest (i.e., they are not between dxDt-1 and dxDt). For example, in the case of individual 1, the above formulae indicate that he spent 33 days in hospital in the month preceding his diagnosis. In reality, he spent 28 days in hospital during that period.
I have found little guidance on other websites. I have reviewed the following link; however, I am not familiar with C#.
Calculate number of days between two dates separated by month
Any assistance would be greatly appreciated!

excel: looking up values using INDEX

i am using the following formula to index my data on sheet 2 and find the matching values which are similar or exact to that which is typed into my cell K22 on sheet 1.
I have used the below code and combined it together using & statements to give me multiple results from seperate columns.
=IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1))
so my finished combined code looks like this:
=`IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1)) & " - " & IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(RIGHT(Sheet2!$A$1:$D$10004,5)=RIGHT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),3)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(RIGHT(Sheet2!$A$1:$D$10004,5)=RIGHT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),3)) & " - " & IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),4)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),4))
so when i perform a search this displays the results like so
Supplier x - Manchester - V0001
i am using ROW() function because i have many of these formulas in seperate rows on my sheet to return multiple search results.
i am also using LEFT() function as a way of telling it to find similar results rather than exact, because someone may type 'Hotel' instead of 'Hotels' etc.
my data on sheet 2 looks like this:
Name Description Location Number
Supplier X Catering Manchester v0001
Supplier Y Hotels London v0002
Supplier Z Catering London v0003
so if i do a search for catering in my cell K22 on sheet 1 i would get a result like this:
Supplier X - Manchester - V0001
Supplier Z - London - V0003
But now if i want to just search for catering suppliers in London, i get the same search results again:
Supplier X - London - V0001
Supplier Z - London - V0003
however it changes the location of supplier x from manchester to london, even though in my column data on sheet 2, supplier x location is manchester?
Can someone please show me why this is happening as it should only be returning the suppliers which have a matching location of London next to them.
Thanks in advance,

Ranking based on 4 columns

i am working on my database in excel...I need to rank the Scorers by considering 4 league scores.I want Ranking based on Scores of leagues with priority from 1 to 4 i.e. who scored most in league 1 would be 1st and if same score in league 1 then consider league 2 scores and so on...my table is as following-
please if u know help me for ranking for my table...
..........A............B...............C................D..................E..............F
======= ======= ======= ======= ================
1.......ID......Score 1......Score 2......Score 3......Score 4......Rank
2...... N01.... 12............... 4................. 3................ 18
3...... N02.... 15............... 4................. 6................ 13
4...... N03.... 12............... 5................. 4................ 11
5...... N04.... 12............... 4................. 3................ 3
6...... N05.... 15............... 5................. 5................ 8
7...... N06.... 16............... 3................. 2................ 3
8...... N07.... 12............... 4................. 5................ 12
9...... N08.... 10............... 5................. 4................ 9
10.....N09.... 13............... 6................. 4................ 17
11.....N10.... 10............... 5................. 4................ 5
For ranking based on 2 fields i have used these formulas:
intermidiate total in F2 to F11 -
=RANK(B2,B$2:B$11,0)+SUMPRODUCT((B2=B$2:B$11)*(C2
and The Rank in G2 -
=RANK(F2,F$2:F$11,1)
But I cannot do it for ranking based on 4 columns...Help plz
Of course the easiest way to do this is simply to do Data > Sort and do 4 levels of sorting (Score1, ..., Score4), but I kinda liked this question to see if I could do it with formulas - A fun challenge...
The nicest way I could think of doing it without VBA would be to add in a few helper columns.
To do this, put the following formulas in:
F2: =B2
G2: =F2 & " - " & SUM(IF(B2=B$2:B$11,IF(C2>=C$2:C$11,1,0)))
And enter G2 as an array formula using ctrl + shift + enter.
Then, drag G2 across till I2 and then, just fill Columns F:I down for your dataset.
Now, if you sort based upon column I, you will have the data ordered as you want it.
Of course, you could make it all in one large and ugly formula in one cell per row:
=B2& " - " & SUM(IF(B2=B$2:B$11,IF(C2>=C$2:C$11,1,0)))& " - " & SUM(IF(C2=C$2:C$11,IF(D2>=D$2:D$11,1,0)))& " - " & SUM(IF(D2=D$2:D$11,IF(E2>=E$2:E$11,1,0)))
but this seems to be a better solution IMHO.
Hope this does the trick!
EDIT:
In response to your comment below, to get the rank, you'll need 2 extra columns (boy, this is getting long :p)...
Put in the following:
J2: =SUMPRODUCT((I2>=$I$2:$I$11)+0)+1
K2: =RANK(J2,$J$2:$J$11,1)+COUNTIF($J$2:OFFSET(J2,0,0),J2)-1
This will give you the rank using non-numeric data.
Hope this fully satisfies your criteria, but it's pretty ugly for sure... Like I said, I enjoyed the challenge of this, but the better way would be to just create a VBA function that took care of this for you...
If you know that the scores will be bounded (e.g. always below 100) you can calculate a weighted score like
WEIGHTED_SCORE = (((SCORE1*100) + SCORE2)*100 + SCORE3)*100 + SCORE4
= SCORE1*100^3 + SCORE2*100^2 + SCORE3*100 + SCORE4
Then rank based on the weighted score

Resources