Nested IF statements assistance - excel

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)))))

Related

NetSuite formula for dates without transactions

I’m trying to create a report that has everyday of the month listed as a column and sums the transaction quantity for that day if transactions exist and enters a 0 in the column if no transactions exist for that day.
Example:
Day
1 2 3 … 28 29 30 31
Sales Rep.
John Doe. 5 0 0… 10 15 0 30
Any ideas how to make this work? I thought about extracting the day from the transaction date but I can’t figure out how to get the days without any transactions. I thought about using current date to extract day but then the formulas would change every day. Ugh!! Help me please!
You can do this with 31 formula fields.
To avoid overlapping months add a formula text column with a formula TO_CHAR({trandate}, 'YYYY-MM')
Create a saved search on sales orders that filters to the month of interest and includes sales rep, date, document number and amount (at least)
for each date you want to report on include a formula numberic column with a formula like case when TO_number(TO_CHAR({trandate}, 'DD')) = 14 then {amount} else 0 end. Give it a custom label of the day number (e.g. 14)
Set summary columns as follows:
Sales Rep - Group
Document Number - Count
Formula Text - Group
each Formula Numeric - Sum
That's all you need to do but the 31 formula columns are tedious so when I do this sort of thing I do the following to create a template of the saved search and then add and adjust the date range (e.g. add filters in the displayed filter region)
Open any scripted record. Usually just view a sales order. If the step below fails try in a sales order in Edit mode. You won't be saving or updating the order
Right click and select 'Inspect'. This opens the developer tools
Find the 'console'. You should see some clear space at the bottom.
Copy and paste the text below into the console and press your enter key.
If all went well the script will print a number
You can then take the search title (Daily Rep Sales in the example code) and paste it in the NS global search. If you run the search you'll see the last 30 days of sales totalled by rep. Add and update filters (e.g. for different date ranges or only for last month or only for this month etc) and then make the search public to share it (or share it with certain users etc)
require(['N/search'], search =>{
var dateCols = [];
for(var i = 1; i< 32; i++){
dateCols.push(search.createColumn({
name:'formulanumeric',
summary:search.Summary.SUM,
label:'Day '+ i,
formula: "case when TO_number(TO_CHAR({trandate}, 'DD')) = "+ i + " then {amount} else 0 end"
}));
}
const searchId = search.create({
type:'salesorder',
title:'Daily Rep Sales',
filters:[
['mainline', 'is', 'T'], 'AND',
['trandate', 'onorafter', 'daysago30']
],
columns:[
search.createColumn({name:'formulatext', formula:"TO_CHAR({trandate}, 'YYYY-MM')", summary:search.Summary.GROUP}),
search.createColumn({name:'salesrep', summary:search.Summary.GROUP}),
search.createColumn({name:'tranid', summary:search.Summary.COUNT}),
search.createColumn({name:'trandate'}),
search.createColumn({name:'amount'})
// whatever drill down fields you want without summary
].concat(dateCols)
}).save();
console.log(searchId);
})

Category Weighting with Total Marks Override

I have a teacher gradebook that uses category weighting (and evaluation weighting within each category). The formula I use to calculate final grade is found in column E here:
https://docs.google.com/spreadsheets/d/1TMsuJWtc4C7tebZGVVyeA4qbmLCnGZRi55ZRJsI-jGE/edit?usp=sharing
What I would like to do is give teachers an option to reduce the total marks for any particular student for an evaluation.
Example:
Evaluation total marks is 10, student mark is 4 (40%)
Teacher decides to make the total marks for this student = 5.
Teacher would enter: 4 [5] where 4 is the student mark and [5] is the new total marks for the evaluation. New percentage is 80%
I have written the formula to calculate the new percentage without issue however I cannot figure out how to get the final grade for this student.
In the linked spreadsheet above, student 1 and student 2 should have the same final grade in column E.
How can I change my formula in column E (starting at E8) to include cases like 4 [5]?
I believe the simplest solution would be to rewrite your formula in column E to use the numbers from the percentage column to calculate the grade, instead of using the complicated string you will find in the marks column.
Example formula that you could use in E8:
=IFERROR(SUMPRODUCT(FILTER(N8:Y8,ISFORMULA(N8:Y8))*FILTER(N$4:Y$4,ISNUMBER(N$4:Y$4))) *100 / SUM(N$4:Y$4),"")
Well that was fun! Using the recommendation of #TomSharpe I came up with this that seems to work:
=IF(ISBLANK($C8),"",IFERROR((
Settings!$E$3*(IF(COUNTIF($N$5:$HD$5,Settings!$D$3)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$3,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$3,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$4*(IF(COUNTIF($N$5:$HD$5,Settings!$D$4)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$4,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$4,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$5*(IF(COUNTIF($N$5:$HD$5,Settings!$D$5)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$5,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$5,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$6*(IF(COUNTIF($N$5:$HD$5,Settings!$D$6)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$6,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$6,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$7*(IF(COUNTIF($N$5:$HD$5,Settings!$D$7)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$7,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$7,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$8*(IF(COUNTIF($N$5:$HD$5,Settings!$D$8)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$8,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$8,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$9*(IF(COUNTIF($N$5:$HD$5,Settings!$D$9)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$9,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$9,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$10*(IF(COUNTIF($N$5:$HD$5,Settings!$D$10)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$10,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$10,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$11*(IF(COUNTIF($N$5:$HD$5,Settings!$D$11)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$11,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$11,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
+
Settings!$E$12*(IF(COUNTIF($N$5:$HD$5,Settings!$D$12)=0,0,SUMPRODUCT($O8:$HE8,$N$5:$HD$5=Settings!$D$12,$N$4:$HD$4)*100/SUMIFS($N$4:$HD$4,$N$5:$HD$5,Settings!$D$12,$O8:$HE8,">=0",$N$3:$HD$3,">=0")))
)/(IF(COUNTIFS($N$5:$HE$5,Settings!$D$3,N8:HE8,"<>")>=1,Settings!$E$3,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$4,N8:HE8,"<>")>=1,Settings!$E$4,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$5,N8:HE8,"<>")>=1,Settings!$E$5,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$6,N8:HE8,"<>")>=1,Settings!$E$6,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$7,N8:HE8,"<>")>=1,Settings!$E$7,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$8,N8:HE8,"<>")>=1,Settings!$E$8,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$9,N8:HE8,"<>")>=1,Settings!$E$9,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$10,N8:HE8,"<>")>=1,Settings!$E$10,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$11,N8:HE8,"<>")>=1,Settings!$E$11,0)+IF(COUNTIFS($N$5:$HE$5,Settings!$D$12,N8:HE8,"<>"
)>=1,Settings!$E$12,0)),"No Grade"))

How to get weighted sum depending on two conditions in Excel?

I have this table in Excel:
I am trying to get weighted sum depending on two conditions:
Whether it is Company 1 or Company 2 (shares quantity differ)
Whether column A (Company 1) and column B (Company 2) has 0 or 1 (multipliers differ)
Example:
Lets calculate weighted sum for row 2:
Sum = 2 (multiplier 1) * 50 (1 share price) * 3 (shares quantity for Company 1) +
+0.5 (multiplier 0) * 50 (1 share price) * 6 (shares quantity for Company 2) = 450
So, Sum for Row 2 = 450.
For now I am checking only for multipliers (1 or 0) using this code:
=COUNTIF(A2:B2,0)*$B$9*$B$8 + COUNTIF(A2:B2,1)*$B$9*$B$7
But it does not take into account the shares quantities for Company 1 or Company 2. I only multiply 1 share price with multipliers, but not with shares quantity).
How can I also check whether it is Company 1 or Company 2 in order to multiply by corresponding Shares quantity?
Upd:
Rasmus0607 gave a solution when there are only two companies:
=$B$9*$E$8*IF(A2=1;$B$7;$B$8)+$B$9*$E$9*IF(B2=1;$B$7;$B$8)
Tom Sharpe gave a more general solution (number of companies can be greater than 2)
I uploaded my Excel file to DropBox:
Excel file
I can offer a more general way of doing it with the benefit of hindsight that you can apply to more than two columns by altering the second CHOOSE statement:-
=SUM(CHOOSE(2-A2:B2,$B$7,$B$8)*CHOOSE(COLUMN(A:B),$E$8,$E$9))*$B$9
Unfortunately it's an array formula that you have to enter with CtrlShiftEnter. But it's a moot point whether or not it would be better just to use one of the other answers with some repetition and keep it simple.
You could also try this:-
=SUMPRODUCT(N(OFFSET($B$6,2-A2:B2,0)),N(OFFSET($E$7,COLUMN(A:B),0)))*$B$9
Here's how it would be for three companies
=SUM(CHOOSE(2-A2:C2,$B$7,$B$8)*CHOOSE(COLUMN(A:C),$F$8,$F$9,$F$10))*$B$9
(array formula) or
=SUMPRODUCT(N(OFFSET($B$6,2-A2:C2,0)),N(OFFSET($F$7,COLUMN(A:C),0)))*$B$9
=$B$9*$E$8*IF(A2=1;$B$7;$B$8)+$B$9*$E$9*IF(B2=1;$B$7;$B$8)
Since in the COUNTIF function, you don't know beforehand, which company column contains a 0, or a 1, I would suggest a longer, but more systematic solution using IF:
=$B$9*$E$8*IF(A2=1;2;0,5)+$B$9*$E$9*IF(B2=1;2;0,5)
This is a bit less general, but should produce the result you expect in this case.

How to calculate values dynamically from Excel table

I have a programming issue in Excel that I don't know how to solve it. I want to create an automatic Delivery Cost Program on Excel that will help me calculating the cost more easily.
The input variables are:
Quantity (Values for 1, 2-9,10-49,50+ and more)
Shipping method
Depending on the Quantity Value and Shipping method, Excel should lookup on the table and return the total shipping cost according the following Table:
------------------------------------------
Delivery | Per shipment fee
------------------------------------------
| 1 2-9 10-49 50+
------------------------------------------
Standard | 2,99 1,89 1,5 1,1
Expedited | 5,99 2 1,75 1,25
Priority | 10,99 3,39 2,25 1,35
------------------------------------------
Let me show you with some examples what I want to get:
1- Example:
- Quantity: 15
- Delivery: Expedited
- Total Cost = 15 * 1,75 = 26,25$
1,75$ is the returned value after looking on the table using the variable Quantity and Shipping Method.
I have tested doing =IF statements but sure that there is an easier way to do it.
I'm not very good on Excel programming so any help will be appreciated
Best regards and have a great day!
Assuming that your table has the delivery types in column A in rows 4 through 6 and that the quantities are in row 3 (columns B through E) the following formula should do it for you:
=INDEX(B4:E6,MATCH(B9,A4:A6,0),MATCH(C9,B3:E3,1)) * Quantity
Note, that the quantities in row 3 must be a number. So, the numbers should be 1, 2, 10, and 50 and not 1, 2-9, 10-59, 50+. There are two possibilities to achieve that:
Create a helper row and hide it (while only showing the row with the "names" as you wish for.
Change the number format on these cells: for the column containing the 2 the number format should then be "2-9" (custom number format). For the number 10 the number format would be "10-49" and the number format for the last column would be "50+". Like this you see what you wan to see while the cells still contain numbers only (for the upper formula to work correctly).

Using If,Then function in Excel

I have a retail store that sells items on consignment for a fee that varies based on Selling Price.
So my question is how do I write a formula that checks the selling price and then charges the correct consignment fee to calculate the net based on the following schedule:
When selling price is over $400 then charge = 20%
When Selling price is $100 to $400 then charge = 30%
When Selling price is under $100 then charge = 40%
BLUF: use nested IF statements (an IF inside an IF) --
Example:
=IF(A2>=400, (A2*0.2), (IF(400 > A2 >= 100, (A2 *0.3), (A2*0.4))))
Or use the below if you suspect someone will foolishly enter a negative number or something nonsensical:
=IF(A2>=400, (A2*0.2), (IF(400 > A2 >= 100, (A2 *0.3), (IF(A2 < 100, (A2*0.4), (0))))))
That may look complex, but let's break it down from the beginning.
The basic formula for the IF statement:
=IF(testCondition, (resultIfTrue), (resultIfFalse))
One IF statement will only allow you to do two of your 3 conditions:
=IF(A1 > 400, (A1 * .20), (A1 * .30))
The above basically says that if the number in cell A1 is greater than 400, then the value in your current cell (e.g. B2) is A1 * 20%. But if the number in A1 is NOT greater than 400, the value in your cell will be A1 * 30%.
But how do we calculate the range you were asking (i.e. 100 - 400) and how do we add in a third possibility (i.e. the possibility that the number is less than 100)?
The answer is to use a nested IF. You can tell the cell what it's value should be if the condition is true, but you can test another condition if the answer is false (i.e. the next IF statement stands in the place of resultIfFalse.
=IF(testCondition, (resultIfTrue), (IF(testCondition, (resultIfTrue), (resultIfFalse))))
The above can handle 3 different scenarios. Out of the IFs above, you could also replace the second IFs resultIfFalse with yet another IF statement, and so on. You can nest up to 64 IF statements.
Extra Resources:
http://fiveminutelessons.com/learn-microsoft-excel/using-multiple-if-statements-excel
http://spreadsheets.about.com/od/tipsandfaqs/qt/nested_if.htm
Nested IF functions are not user friendly and require hardcoding your variables (percentages). My suggestion would always be to have a small table of values elsewhere: eg. put the following in A1:B3
0 0.4
100 0.3
401 0.2
Assuming your data is in D1 you can use the following formula in E1 and drag down if necessary
=INDEX($B$1:$B$3,MATCH($D1,$A$1:$A$3,1))
This way you can change your boundaries/ add more conditions easily without more nested IF statements
Try using this instead:
=IF(B1<100,B1*40%,IF((B1>=100)*AND(B1<=400),B1*30%,IF(B1>100,B1*20%,"Invalid Price"))
This formula contains nested-ifs and a logical AND condition which will give the result.

Resources