Excel: count the number of cells in a column until their sum is greater than a set value - excel

I have a list of consecutive events in one column and their durations in the adjacent column. I want to count the number of times a particular event occurred in a certain length of time.
For example:
Col Event Duration
1-- Contr 8
2-- Relax 5
3-- Contr 12
4-- Relax 6
5-- Contr 10
6-- Relax 5
In this example I want excel to start from row 6 and go backwards, summing durations until the value is over 30 and return the number of times Contr occured over that time period. Here the answer is 2.
Here's a link to an example spreadsheet with more realistic values: https://1drv.ms/x/s!AiOl_zwCwrAmgcgQqCPaOY5WzMZTGQ
(The threshold value would be 900 instead of 30.)
Thanks. Hope I asked the question right.

I would have to use a helper column to work out the totals under the current row. I don't mind if the sum including the current row is 30 or more, as long as the sum under it is less than 30.
So in D2:-
=SUM(C3:C$100)
Then it's just a countifs:-
=COUNTIFS(B2:B100,"Contr",D2:D100,"<"&30)

Related

Only show the sum of a column if there are at least 3 records in another column

I have 3 Columns of data. Column E = Duration. The user will enter a number of days (Duration) for 20 employees. Column F = Pay. List of wage for each employee. Column R = Pay Total. This is a calculated field based on the number of days (Duration) and the employees pay (Pay).
To keep my employees from finding out their coworkers pay I only want to see a sum for Column C if there are at least 3 records in Column A.
I found this Sum only if 3
From that answer I tried to use =IF(COUNTIF(E2:E15,">2"),SUM(R2:R15))
What this does is only returns records with a duration of greater than 2 days. I don't care about the number of days. I want the indicator to be that there are 3 cells populated in this column.
I think the only issue with the formula is the CountIF part. I need to know what I should use to count cells not days.
Screenshot of My Sheet
In the image above you can see that it's returning a sum bc both records are greater than 2. Like I said before I don't care what number is in the cell I just want to see the sum if there are more than 2 cells populated in that column.
Thanks for any help
As per my understanding of the question, I came up with this solution. Give it a try.
=IF(COUNT($E$2:$E$15)>2,SUM($R$2:$R$15), 0)
This formula would give what you want
=IF(COUNTA(E2:E15)>2,SUM(R2:R15),"")
This would show sum only if count of non empty cells is greater than 2 in Range "E2:E15" else it would show empty.

Find row when Cumulative sum reaches certain value with condition

I have a table with 3 columns Date, Item and Number. Each row indicates how many items of each Item was received on that date. I am trying to find the date on which cumulative sum reaches 100 or more in that month. Each month will have a target for each item which will be saved in another sheet but for simplicity we can assume that its a fixed number of 100.
Example Data:
Date Item Number
1/2/2018 A 10
2/2/2018 B 10
2/2/2018 A 15
5/2/2018 C 25
6/2/2018 A 50
7/2/2018 B 10
7/2/2018 C 10
8/2/2018 A 25
9/2/2018 A 20
I am looking for the formula which should act on the data similar to above and give the result as 8/2/2018 which is the date on which the cumulative sum for Item A reached 100.
Each month will have different target number, and will have different number of entries.
I have tried using SUMIF and adding a additional column etc but this data is just part of a big data and each item limit is saved in a different sheet etc which is not easy to merge. Thanks in advance for help.
In Excel only, you can use Offset to develop an array of items and numbers containing 1,2,3...9 rows and then SUMIF to add each of them up. Then use Match to find the first one =100 and Index to find the matching date (in F2):
=INDEX(A2:A10,MATCH(100,SUMIF(OFFSET(B2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1)),"A",OFFSET(C2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1))),0))
Must be entered as an array formula using CtrlShiftEnter.
EDIT
To find the first sum which is >=100 (in G2):
=INDEX(A2:A10,MATCH(TRUE,SUMIF(OFFSET(B2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1)),"A",OFFSET(C2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1)))>=100,0))
Sum which reaches exactly 100
Sum which does not reach exactly 100 (the number in row 9 has been changed to 24):

How to calculate the daywise average and multiply it to number of rows in that particular day

I have daywise excel data of four months which contains hourly data from 10 AM to 3 PM or sometimes 10 AM to 2 PM....1PM ..... like wise it is varying. The column A contains the date, Column B contains the time and column C and D has the data which i want to average for each day and multiply it to the number of occurrence.
For example If I have a data in column C and D for 17 Oct from 10 AM to 3PM (6 Hours)..Then i want to average these hourly data for a day and multiply it by 6. Since my interval of hourly data is not fixed, that is why i want a code which can average the daywise data and multiply it to the number of occurrence. I want to average the data 1 and data 2 for each day and to multiply its average by the number of occurrence of data in that particular day
I could not exactly get what does "average these hourly data" means since Average basically means summing all data within a day and dividing them to the occurrences. If you again multiply by the number of daily occurrence, you will get the summed value again.
Apart from above unclear point, un-merging all column B cells and filling all your rows with date data will be very helpful in order to form a quick sum or average formula based on the date conditions.
After doing above step, you may enter the below formula to E2 to get the sum of Col:C, for all data dated A2; 17-Oct.
=SUMIFS(C:C,A:A,A2)
And you may get the occurences on the date of your row data, you should use the formula and copy down:
=COUNTIFS(A:A,A2)
In combination of above 2 formulas, you may calculate the averages and/or date occurrences. I may write an exact solution if you may enter your requested values into COL:E and provide a screenshot.

Quantifying conditional duration of values in excel

I am trying to analyze blood pressure that is taken every minute, and determine how long the values are within a certain range, consecutively. I have the data set up in excel for the moment. I have color coded the values based on the ranges I would like to quantify. I know that if I do a simple "=countIF) function I can get the total number of times these values meet the criteria. But what I want to do next is quantify for how long the values fall within a specified range, consecutively.
This shows values in columns in excel, where each column is a different patient, and the heat map are the value conditions to help me visualize if certain thresholds occur for longer times than others. But I want to find a way to quanitify this in excel, if possible. Any help would be much appreciated.
The final result I am looking for is to be able to measure how much time each patient sustains a specific category of blood pressure to know if certain ranges are more prolonged than others (e.g. blood pressure is between 120-130 for 30 minutes). So in the spreadsheet above, assuming each cell is a 1-minute bin, for column HU, BP is between 120-130 for 3 minutes (rows 2-4), and again for 16 minutes (rows 6-22). In column HS, blood pressure is above 140 (black) for 7 minutes.
I want to find a workflow to quantify these durations so that I can get a summary of the number of consecutive 1-minute bins (each cell) at a specified range/threshold for each patient (column)
First, I would create another sheet -- let's call it "Thresholds" -- with thresholds of bloodpressures in ascending order in column A.
Put a category number next to each value (in column B)
For example:
0 0
90 1
100 2
105 3
110 4
115 5
120 6
125 7
... etc.
Back in the other sheet, add a new column next to each bloodpressure column. So you
would have a new column HR next to HQ.
Put there a formula that looks up the category for the value in HQ, from sheet "Thresholds".
You can use VLOOKUP for that. For example in row 2:
=VLOOKUP(HQ2, Thresholds!$A$1:$B:$1000, 2)
Then add yet another column, HS it will be.
In there make a running count for same category rows, like this (for row 2, I assume you have used row 1 for column titles):
=IF(HR1<>HR2, 1, HS1+1)
Drag down this formula to the column. This formula checks if this row has a different category of blood pressure than the previous one. If so, it
sets the counter to 1 (it is the first instance in this running series). In the other
case it takes the value of the counter in the previous row and adds 1 to it.
Repeat this for the other columns (inserting 2 new columns next to each).
This will already give you a start for further analysis.

Excel Calculations

Is there a way I can have an excel track the number of times a number has been entered? For instance, if the number 1 is entered into a column 10 times it would display that in the legend. And if the number 10 was entered into a column 2 times it would display that total in the legend.
The goal is to track each number as a unique integer 1 - 35.
You can use =COUNTIF(A:A,"10") to count the number of 10s in Column A.
But you'll need 35 COUNTIF functions in 35 cell, and that only for 1 Column.
How do you plan to display that Legend?

Resources