Excel 2007 Sumproduct foreach day in column? - excel-formula

I currently have a spread sheet will be populated without a set size when it comes to row count. I have a column for time that is populated ever time an entry is made.
Ex:
Transition Time State Reason Code Duration
06/01/2015 06:43 AM Logged-in 0 0:00:00
06/01/2015 06:43 AM Not Ready 32760 0:00:43
06/01/2015 06:44 AM Logout 5 0:00:00
06/01/2015 06:46 AM Logged-in 0 0:00:00
06/01/2015 06:46 AM Not Ready 32760 0:01:47
06/01/2015 06:47 AM Ready 0 0:00:00
06/01/2015 06:47 AM Reserved 0 0:00:06
06/01/2015 06:48 AM Talking 0 0:06:59
06/01/2015 06:55 AM Not Ready 6 0:02:58
06/01/2015 06:58 AM Ready 0 0:00:00
06/01/2015 06:58 AM Reserved 0 0:00:01
06/01/2015 06:58 AM Talking 0 0:09:18
06/01/2015 07:07 AM Work 0 0:00:05
Now this will continue all the way through the report. Generally it is a month long, but can be longer. I was able to get the values for the month based on other columns.
Ex:
=SUMPRODUCT(--(C:C=6),--(B:B="Not Ready"),(D:D))
This will give me the whole reports value. I need to get this where it will count for 1 day at a time.
pseudo:
DateTime selectedDay = current row
DateTime currentDay = current day from row;
foreach(DateTime day in Transition Time)
{
if(selectedDay <= currentDay)
{
//SUM to CELL - Array prefered
}
else if(selectedDay > currentDay)
{
currentDay = selectedDay
}
}

Please consider the following formula to calculate total duration in seconds for total users "Not Ready" with Reason Code 6 on a particular day set by date in cell H2:
{=(SUM(IF(((B:B="Not Ready")*(IFERROR(INT(A:A),0)=H2)*(C:C=6))=1,TIMEVALUE(D:D),0)))*86400}
Please note that the curly brackets are not inputed manually but when entering formula as array formula using CTRL + SHIFT + ENTER.
I have taken advantage of being able to multiply booleans (true or false, 1 or 0) as AND was calculating throughout the whole array. This gives me a 1 for rows where all conditions are met. Using an IF(array=1,"Duration range") I'm able to extract all relevant values and with which I SUM throughout the final array and multiply by 86400 (number of seconds in a day) to arrive at the final calculation. Regards,

Related

Count values of an Excel column in different ranges

I want to count number of values in different ranges in an Excel column.
Example 1:
Imagine I have some data in 40 rows, each one happened in different time of day. Like the below image:
now I want to count number of row repeated in different ranges, for example, count number of rows that have time between 12:00 to 18:00, again count 18:00 to 00:00, and more to 11:59 (next 12:00)
Time range
Count
00:00 to 6:00
?
06:00 to 12:00
?
12:00 to 18:00
?
18:00 to 23:59
?
Finally I have a table with 4 rows that shows how many row I have in those ranges and I can create a chart by that.
Example 2:
Count people based on age range. result would be like this:
Age range
Count
12 to 18
3
18 to 25
5
25 to 35
4
35 to 45
1
45 to 60
2
P.S:
I used countif with logical AND, but it didn't work. like this: =COUNTIFS(C:C,"AND(<00:00, >2:00)")
A more correct use of COUNTIFS (which is different from COUNTIF), would be :
'Counts values strictly between 00:00 and 2:00
=COUNTIFS(C:C,">00:00",C:C,"<2:00")
Hope it helps

How to count items in Excel within a date range or without an end date

Note: date formats are DD/MM/YYYY
I have a list of records, each with one column for a start date, and one for an end date.
Every record has a start date, but if an item is current it has no end date and the end date cell is blank.
I want to write a/some formulas to determine how many records were a given age at a given date, rounded down to the nearest whole year.
So for example, how many records were 0-1 years old at the date at (cell reference R1), and then how many were 1-2 years, 2-3 years etc.
I want this to be reusable so that I can update the date at R1 each month and it recalculates automatically. This is easy enough for R1=TODAY, as I can assume all end dates are in the past, but for R1=EDATE(TODAY,-12) it becomes trickier.
As an example, in the yellow highlighted cell I want to calculate how many records were between 1&2 years old as of 30/06/21 (S1), AND were current at the time (i.e. exclude from the count any records that have an end date before 30/06/21).
The blue highlighted area is my data, the green area is what I'm trying to calculate. I don't mind adding an extra data column or two if it assists in the calculation, but I don't want to have to add an extra column for every year that I'm trying to calculate, if it can be avoided.
Start Date
End Date
Years (as of 30/06/2022)
Age
30/06/2022
30/06/2021
30/06/2020
30/06/2019
30/06/2018
30/06/2017
30/06/2016
30/06/2015
30/06/2014
30/06/2013
20/09/2021
0.77
13
0
7/09/2020
4/12/2020
0.24
12
0
6/08/2019
2.90
11
0
17/02/2020
2.37
10
0
1/04/2019
3.25
9
0
16/03/2020
18/11/2020
0.68
8
0
17/08/2021
19/11/2021
0.26
7
0
23/08/2022
-0.15
6
0
16/11/2020
1/04/2022
1.37
5
0
20/04/2020
21/10/2021
1.50
4
0
7/05/2019
26/02/2021
1.81
3
2
29/06/2020
7/01/2021
0.53
2
5
16/08/2021
20/04/2022
0.68
1
5
0
13
I created a table for the data (insert table) --> tblData
=LET(calculatedAge,MAP(tblData[Start Date],tblData[End Date],
LAMBDA(startdate,enddate,
ROUNDDOWN((MIN(IF(ISBLANK(enddate),E$1,enddate),E$1)-startdate)/365,0))
),
filteredAges,FILTER(calculatedAge,calculatedAge=$D2),
IFERROR(ROWS(filteredAges),0))
The MAP-function returns the calculated age per target date (E$1) - rounded down.
It simulates a helper column - that then can be filtered.
Thanks to #Robert Mearns for the FILTER-hack - as COUNTIF doesn't work in this scenario (s. Using LET with COUNTIF and Array, e.g. MAP)

Excel Average Calculation of a Moving Criteria Range

I need to create a logic excel formula that calculates the average of 3 months prior to a specified start date. There are multiple start dates. For instance:
For ID 1, The Start Date is May-2021. I would need for the logic to calculate the average between Feb-2021 to Apr-2021 to get 91.67. For ID 2, the Start Date is Jun-2021, so I would need to calculate the average of Mar-2021 to May 2021 to get 108.33. I also would need to calculate the average of 6 months prior in a separate column.
ID
Start Date
Calculation Result
Jan-2021
Feb-2021
Mar-2021
Apr-2021
May-2021
Jun-2021
1
May-2021
91.67
50
100
75
100
25
0
2
Jun-2021
108.33
0
25
100
175
50
125
3
Apr-2021
83.33
100
150
0
75
0
200
Any help is greatly appreciated! (Not opposed to VBA suggestions either)
use INDEX to create the range.
=AVERAGE(INDEX(D2:I2,MATCH(B2,$D$1:$I$1,0)-3):INDEX(D2:I2,MATCH(B2,$D$1:$I$1,0)-1))
Or if they are true dates we can use AverageIfs:
=AVERAGEIFS(D2:I2,$D$1:$I$1,">"&EOMONTH(B2,-4),$D$1:$I$1,"<="&EOMONTH(B2,-1))

Using MOD with Time values to determine time differences that transition midnight

I created an Excel Spreadsheet with a Total Time for the Duration of the Shift ie 8:30-17:30.
Then I created this formula
=(MOD([#[Supposed Shift End]]-[#[Supposed Shift Start]],1))*24
with Format cells -> Number 2 decimal places. This gives me the [Total Supposed Shift Hours]
Giving me Duration of the Shift that needs to be covered.
Now I also created another column for the ACTUAL time the shift covered
=(MOD([#[Actual Time End]]-[#[Actual Time Start]],1))*24
This gives me the [Total Actual Time Hours]
For the Actual Time End and Actual Time Start When the employee DIDN'T show up we entered 0 for both cells with the same cell format Number -> 2 decimal places
The Problem:
This is the formula I wrote to subtract these 2 Columns
=(MOD([#[Total Supposed Shift Hours]]-[#[Total Actual Time Hours]],1))*24
Why when I subtract say the [Total Supposed Shift Hours] 9.00 - the [Total Actual Time Hours] 0.00 = 24.00 ???
9 - 0 = 9 not 24.... sigh
Will the formula be affected if the time goes from previous night 21:00 to 8:00 with the MOD formula?
Sample data (as requested)
Note: Nomenclature differs from description above: Open = Supposed and Covered = Actual
Service Date
Open Post Start
Open Post End
Total Hrs Missing
Covered Post Start
Covered Post End
Total Hrs Covered
Category
Hours Not Covered
02/06/2021
16:00
00:00
8
16:00
03:00
11
A
0
04/06/2021
16:00
00:00
8
00:00
00:00
0
A
0
10/21/2021
10:30
00:00
13.5
18:00
19:30
1.5
B
0
Initial Answer
A minor point first: You don't need to wrap the MOD function in brackets. As the function already produces a result to the *24. Thus the following works just fine:
=MOD([#[Supposed Time End]]-[#[Supposed Time Start]],1)*24
To your question: Your non-working formula reads as if it simply wants the difference (in hours) between Supposed and Actual. If that's so, simply do this:
=[#[Total Supposed Shift Hours]]-[#[Total Actual Shift Hours]]
EDIT: Using the (now posted) table, I've constructed what I think it is you're trying to doRefer to Sample results image below.
Formula in Colum E: =MOD([#[Open Post End]]-[#[Open Post Start]],1)*24
Formula in Colum H: =MOD([#[Covered Post End]]-[#[Covered Post Start]],1)*24
Formula in Colum J: =[#[Total Hours Missing]]-[#[Total Hours Covered]]
Sample results:
Now: If Column J (i.e. the response to your core question) isn't the result you're after, can you tell me what it is you would expect there (using actual expected values for each row).
Notes:
Your table column header Total Hours Missing is somewhat confusing.
But, I'm reading that a Post Duration (Duration of Shift in your original parlance).
If I understand what transpired correctly, the "spanner in the works" was #P.b suggestion to remove MOD. Revert your formulas in columns E and H as shown above.

Excel Time Comparison and Subtraction

I am trying to do a time subtraction in excel of 30 minutes and I am running into a speed bump. So the table I have are as follows.
Table "Schedule"
Column 1 is day of the week (Mon-Sun) (formated as general, as this is plain text)
Column 2 is start time of the shift (formated as h:mm AM/PM)
Column 3 is end time of the shift (formated as h:mm AM/PM)
Column 4 is duration of the shift (start to end) (formated by formula (TEXT(col3-col2,"h:mm")) )
Column 5 is paid hours (if the total hours is over 6.5 then subtract 0.5 hours for an unpaid lunch) (formula IF(col5>"6:30",col5-"0:30",D5) )
The issue is any time allotment over 10 hours start to end (where column 4, the duration hits 10 hours) no lunch is subtracted at all.
So...
Start 9:00 AM, End 6:59 PM, Hours Total 9:59, Hours Paid 9:29
But...
Start 9:00 AM, End 7:00 PM, Hours Total 10:00, Hours Paid 10:00
and that should obviously not happen. I can't find anything on google so I figured the excel gurus here may have some advice.
Thanks!
If your time columns are stores using excel's dedicated time format, this should be straightforward. Mixed data types are likely your problem.
First, be sure your time columns (columns 2 and 3) are set using the time function, i.e.,
=time(hours,minutes,seconds)
Then, you should be able to add and subtract easily.
Column 4: = column 3 - column 2
... then subtract 30 minutes also using the time() function:
Column 5: = if(column 4 > time(6,30,0),column 4 -time(0,30,0),column 4)
Excel stores time values from 0 to 1. So 24 hours=1, 12 hours=.5 etc. That means 6.5 hours=0.270833333 and .5 hours=0.020833333. As a result you can just do a simple if statement.
=IF(D2>0.270833333,D2-0.020833333,D2)
To turn it into a time format, is to just use excel's time formating options.

Resources