How to sum under certain conditions in Excel? - excel

I have a formula in Excel that I'm trying to work out. The formula is meant to return a sum under certain conditions.
If the salary is less than the limit amount and is greater than 30 hours worked, it is meant to sum the cells. If false then it is meant to return a calculation, but this needs to return by minus itself from a sum total to get to a final result.
The below formula only returns the reduced rate not the sum total - reduced rate = final result:
=IF($G$7*52<$K$5*(AND($C$4>30)),SUM($K$7:$K$9),($G$7*52)-$K$5)*$K$6
I can't seem to manage to think how to return sum total is their a formula I can use that could involve this part of the formula:
($G$7*52)-$K$5)*$K$6

Something like this?
=IF($G$7*52<$K$5*(AND($C$4>30)),SUM($K$7:$K$9),SUM($K$7:$K$9)-(($G$7*52)-$K$5)*$K$6)

Related

Excel - standard deviation where source cells are a count

I have some data that looks like this
Condition 1
Condition 2
Condition 3
Condition 4
Condition 5
0
0
0
70
0
0
50
10
0
0
120
0
0
5
5
Where the value in each cell is the number of meters of an asset that is the given condition. Or in other words, a count of the number of meters that are a '4'.
How do I calculate a standard deviation for this? Obviously the std.dev would be '0' for the first row, higher for row 2, and fairly low for row 3.
Something similar to REPT, but that repeats a value x times in a formula?
I considered a helper column but the number of meters that there are in total makes this impractical.
I am not a math expert, but I can show you how to "make a range of numbers" based on the criteria shown, using Excel 365.
Suppose your data is in the range B2:F4 as shown below. In cell G2, enter the following formula and drag it down:
=STDEV.P(--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]"))
The above will calculate the standard deviation using the STDEV.P function, but I am unsure if this is the right function to use as there are many other variations to the original STDEV function.
Regardless, the following part of the formula is able to return a range of numbers as desired:
=--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]")
You can view this question and the answer by JvdV to understand the use of the FILTERXML function.
Another way of doing it is to use the alternative SD formula
which would give you
=SQRT((SUM(A2:E2*COLUMN(A2:E2)^2)-SUM(A2:E2*COLUMN(A2:E2))^2/SUM(A2:E2))/SUM(A2:E2))
for the population standard deviation.
The Excel 365 version using Let is more readable I think:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
sumxsq,SUM(mpy*x^2),
sumsqx,SUM(mpy*x)^2,
numerator,sumxsq-sumsqx/n,
SQRT(numerator/n)
)
A bit less obviously, you could get it from the original formula
=SQRT(SUM(A2:E2*(COLUMN(A2:E2)-SUM(A2:E2*COLUMN(A2:E2))/SUM(A2:E2))^2/SUM(A2:E2)))
Again, in Excel 365 you could write this as:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
xbar,SUM(mpy*x/n),
numerator,SUM(mpy*(x-xbar)^2),
SQRT(numerator/n)
)
Change the denominator to
(SUM(A2:E2)-1)
for the sample standard deviation.
I ended up figuring it out.
I added a column which calculated the average. (Say column F)
I then had a formula like this
=SQRT(SUM(A2*POWER((1-F2),2),B2*POWER((2-F2),2),C2*POWER((3-F2),2),D2*POWER((4-F2),2),E2*POWER((5-F2),2))/SUM(A2:E2))
Essentially this calculated the variance from the mean for each condition value, multiplied by the number of values (e.g. number of meters) of asset that are that particular condition, then did the normal other standard deviation calculations (sum, divide by total, square).

How can I add or subtract using case formulas?

I have sales metrics tracking using case formulas to give me a sum when a status is updated in system notes. If you look at the image, what I'm trying to accomplish is to add a column that would show total appointments (first formula) minus the set number of '20'. I want to see the difference between the sum and the sales target of 20
Set the Summary Type to Min and sum the result using the formula. Then you can use arithmetic on the sum.
SUM(CASE ... END) - 20
Wrap your case formula in SUM(your case formula) - 20.
Change NetSuite's SUM to MINIMUM (SUM will work but probably return unexpected results on the Total row)

Custom SUMPRODUCT()

I have the following table:
My objective is to spread out the 10,000 units across the 5 months, given the weightings below each month. The row adjacent the 10,000 is my best attempt at getting this (I have spent a few hours on this). The yellow is what I am after.
The logic I have tried to use to get the calculation is as follows: Calculate the even spread across the months (in this example 10,000 / 5 = 2,000 = X). Multiply each month weighting to get the weighted amount (in this example to get M2 = 1,600 and M4 = 3,000: X + (X * M2 weighting) etc). You can then take the total 10,000 minus the summation of these which will give you 5,400, which you can then distribute across the months don't don't have a weighting. There must be an easy way to do this with a SUMPRODUCT but I can't seem to figure it out.
My best attempt so far is this:
=IF(B3=0,SUMPRODUCT(ABS((10000/5)*$B3:$F3)),(10000/5)+((10000/5)*B3))
Try the following:
Formula in B3:
=IF(B$2=0,($A3-SUMPRODUCT(($B2:$F2<>0)*(($A3/5)*(1+$B2:$F2))))/COUNTIF($B2:$F2,0),($A3/5)*(1+B$2))
Drag right.
Logic:
=IF(B$2=0,<true>,<false>) - Check if cell above equals zero
If above is false (so other than 0) then: ($A3/5)*(1+B$2) - First divide (10000/5) and multiply that outcome by (1-<percentage>)
If IF yields true - Check which cells in range are other than zero and multiply by the same logic as per step 2. The sum gained with SUMPRODUCT can then be deducted from 10000 and devided by the count of cells that actually do hold zero (hence the COUNTIF).

Nested MIN within SUMIF formula

Problem: I can't seem to get the > MIN formula to work within SUMIFS
Requesting: Formula that will return the SUM of balloons IF the dollars amount is greater than the MIN
Expected output = 510,000 balloons
Note: This is just an example problem for easy comprehension. In reality the data set is much larger and I will include multiple IFs.
You can sum the entire range and then just subtract the values from the range where the dollar amount is equal to the min $.
If your min value is repeated, they will all be removed from the sum.
=SUM(C:C) - SUMIF(B:B,MIN(B:B),C:C)
I believe you were attempting to do this in one sum equation which would look like this
=SUMIF(B:B,">"&MIN(B:B),C:C)
Even easier:
=SUMPRODUCT(--(B:B>MIN(B:B)),C:C)

Excel SUMIF criteria within range of numbers

I was wondering how to represent the criteria argument in the function =SUMIF(range, criteria) as instead of ">0" which represent greater than zero, which would add all numbers in the range that are greater than zero. I was wondering how to make it within the range of zero to 8, so "8>0", or something, but I have been googling for hours and cannot find a solution that doesn't involve doing whacky things with SUMIFS which involves other arrays which I do NOT want to get into because I feel there's a simple solution to this that I'm missing...
Theres ">=NUM" "<=NUM" ">NUM" and "<.NUM"
how do you make it require two of these?
Is there any documentation on this anywhere?
I agree with #user3240704 that SUMIFS is the way to go.
If you insist on using SUMIF only then you can use the following logic:
take the sum of the entire range
deduct the sum of values <-10
further deduct the sum of values >0
Which is the inverse of saying
only the sum the values >=-10 and <=0
The formula is:
=SUM(A1:A11)-SUMIF(A1:A11,">0",A1:A11)-SUMIF(A1:A11,"<-10",A1:A11)
E.g.
More info here
=SUMIFS(A1:A11,A1:A11,">=-10",A1:A11,"<=0")
SUMIFS has many (in this case two) conditions, broken down as follows:
=SUMIFS(A1:A11 - SUM() whatevers in A1:A11
, - That match the following conditions
A1:A11,">=-10" - ALL numbers in A1:A11, that are greater than OR equal to -10
, - AND
A1:A11,"<=0" - ALL numbers in A1:A11, that are less than OR equal to 0
)

Resources