Calculate results and then count them based on a criteria in one formula - excel

I have the following Excel spreadsheet:
A B C D E
1 Sales 500 200 400 300
2 Difference (Helper Row) -60% 100% -25%
3
4 Criteria: -20%
5 Result: 2
Formulas:
C2 = C1/B1-1
D2 = D1/C1-1
E2 = E1/D1-1
B5 = COUNTIF(B2:E2,"<"&-0.2)
In Row 1 you can see the sales over the last 4 periods. In Row 2 the difference between the sales is calculated using the simple formulas described above.
In Cell B5 I want to show the number of differences (Row 2) which are below the criteria in Cell B4. In this case the result is 2 because -60% and -25% are below the criteria of -20%.
All this works perfectly so far. However, I would prefer to have this system without the Helper Row 2 that I currently use to calculate the differences between the sales in Row 1.
Do you know a formula that gives me the exact same result but calculates the differences automatically and then counts them if they meet a certain criteria?

Try the following
=SUMPRODUCT(--(C1:E1/B1:D1-1 <B4))
If dealing with potential 0s in Sales
={SUM(--(IFERROR(C1:E1/B1:D1-1,0)<B4)*--(C1:E1>0))}

Related

Formula Help SUM Based on Given Value

i have data in Column A - Days and Column B - Sales i want calculate running total based on Days Value like
Column A Column B
Day1 150
Day2 200
Day3 175
Day4 250
i want total running sum in Column E Based on Value in Column D
here i applied this formula to running sum based on cell value
=SUM($B$2:B2,INDEX($B$2:B5,MATCH($D$2,$A$2:A5,0)))
here i have getting wrong result like if i enter (Day3 in Cell D2 getting result in Cell E2 - 325) it's wrong
The syntax is just a bit off, you should add up the range from B2 to the position found by the match, in this case B4:
=SUM($B$2:INDEX($B$2:$B$5,MATCH($D$2,$A$2:$A$5,0)))
This works because Index returns a reference and can be used as one end of a range.

Formula to calculate a sum of differences and count them

I have the following Excel spreadsheet:
A B C D E F G H
1 Sales 500 700 600 450 550 600 500
2 Helper Row (Differences) 40% -14% -25% 22% 9% -17%
3 Helper Row (Counts) 0 0 1 0 0 0
4 Count Result 1
In Row 1 you can see the sales over different periods. In Row 2 the difference between the sales are displayed. (e.g. formula in C2=C1/B1-1).
In Row 3 the formula indicates 2-Following-Periods in which in total the sales drop by >-20%.
In the case above this applies to cell E3 because the sales in cell D2 drop by -14% and in the next period in cell E2 by -25% which makes a total drop of those two periods by -39%.
The formula I use in Row 3 is for example E3=IF(SUM(D2:E2)<-0.2,1,0).
Eventually, I use a sum function in cell B4 (B4=SUM(B3:H3)) to count how often the above described criteria is met.
All this works perfectly so far. However, my target now is to get rid of the Hepler Row 2 and Row 3.
Do you know a formula that gives me the count result which meets the above described criteria?
Assuming that your above demonstrated numbers are in cell B1:H1, you can use following formulae to achieve result without helper cells.
Array formula (CTRL+SHIFT+ENTER and not just ENTER)
=SUM((((C1:H1-B1:G1)/B1:G1)<-0.2)+0)
Or for normal ENTER
=SUMPRODUCT((((C1:H1-B1:G1)/B1:G1)<-0.2)+0)

Formula to count Text and dates by multiple criteria

I have been trying to create a formula that will count the number of occurrences based on multiple criteria. In the display below I am looking to populate cell C5 with the number of rows that meet a given criteria. In this case, when the start date is between C1 and C2 and the team is Green or Blue or the Department is WAZ. I have been able to get counts to work based on just the date or just the team but have been unable to find a solution with all 3.
Countifs is what I have been trying but without success. I can only get a portion of the criteria to work. As soon as I add in the date part it errors out.
Start 12/21/14 12/28/14 1/4/15
end 12/27/14 1/3/15 1/10/15
Project ID start date end date team Department
1 1/7/15 6/26/15 Blue SRT
2 12/27/14 1/23/18 Green DFT
3 1/8/15 3/20/15 Red DFT
4 1/3/15 6/20/15 Red WAZ
5 12/29/14 7/12/15 Blue DFT
Supposing that you have the following criteria:
J5 = red
J6 = DFT
and your are looking for dates (start & end) in C1 and C2.
I am using my example, please follow the data in the image below:
so put this formula in cell C3, which shows the number of rows for your query:
=COUNTIFS($C$5:$C$11,">="&C1,$D$5:$D$11,"<="&C2,E5:E11,J5,F5:F11,J6)
as you see the formula yields 2 because there are only two rows that match these conditions. (the rows are in bold, rows 6 and 7).
So basically a countifs can contain several criteria:
COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2, criteria_range3, criteria3 ...)

PercentileIF Excel (or rangeif)

A B
1 5
2 10
2 15
3 20
I want to calculate percentile for a column of values B if A is equal say 2. That's I want to get range of B2,B3 and calculate percentile of this.
So basically the question is: how do I select range in one column with the checking with another column?
I.e. it works perfectly with SumIf and CountIf, I just need the same with PercentileIf. Thx!
This will give you the 25th percentile of A1:A6 for all cells where the value in B1:B6 equals 2:
=PERCENTILE.INC(IF(B1:B6=2,A1:A6,""),0.25)
It's an array formula and must be entered with Ctrl-Shift-Enter.

Averaging daily varying column in excel vb

Every day I have to analyze two cols of numbers.
Cols differ each day.
Col 1 has no.'s from 1 to 5, eg. Day 1 there are 150 x 1's and 200 x 2's, etc. Day 2, 350 x 1's and 85 x 2's etc.
Col 2 has values between 1 and 99.
I need to count how many 1's there are to obtain a 1's average, 2's ave., etc. So far I have tried to write a vb program (excel 2010) - I have written the following:
Function Phil2()
ct = 0
For X = 2 To 10
If ax = 1 Then Let b15 = b15 + bx
ct = ct + 1
Next
End Function.
But I cannot get it to display. Can anyone help me?
I want the average of the 1's in cell b15.
See the formula bar for what is in cell E1. If you don't have XL2007 or above, the formula becomes:
=IF(ISERROR(SUMIF($A$1:$B$10,D1,$B$1:$B$10)/COUNTIF($A$1:$B$10,D1)),"",SUMIF($A$1:$B$10,D1,$B$1:$B$10)/COUNTIF($A$1:$B$10,D1))
You could also make more "automated" by using Dynamic Named Ranges for your ID (1,2,3..) and data (%) sets, that change each day.
OK, It works fine - I modified your formula to:
=IFERROR(AVERAGEIFS(B$16:B$500,$A$16:$A$500,$A2,B$16:B$500,">0"),"")
and it works perfectly for values 1, and 2. So that's a great start. I placed the formula cells on top: so in a1 I typed cow no., in b1 %Milk, in c1 %weight, etc.. In a2 I typed 1, a3 2, a4 3 etc.. In b2 your formula etc.. My next challenge is to lump together all cow types 3 to 11. So next to cow type 1 we have a % for each category, same for cow type 2, etc.. But the 3rd row must have an average for all categories 3+. Raw data cow types are in a10 down, vals in b10, c10, etc.

Resources