Count values of an Excel column in different ranges - excel

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

Related

Allocating staff to 30 minute intervals

I’m trying to create either a spreadsheet or macro that allows me to put and employee start and finish time in and then show me by each half hour how many half hours they are in.
For example;
Employee 1 - 08:30 to 10:15
The output I would want is;
08:00 0
08:30 1
09:00 1
09:30 1
10:00 0.5
10:30 0
11:00 0
So between 8:30 and 9:00 shows as one because that employee was in during that half hour. But between 10:00 and 10:30 it shows 0.5 because the employee was only in for half of that period
Then as I add more data it tells me which half hours they are covering.
I’ve tried using the ceiling and floor values, counta, countif, countifs, v and hlookups but just can’t get the desired effect.
I’m guessing it would need to be a macro.
Assuming C1 and D1 contain the start and end times of a shift and column A contains the times, use the following formula in column B:
=IF(A2>D$1,C2,IF(AND(A2>=C$1,A3<=D$1),1,MAX(0,A3-D$1)/(1/48)))
Limitations: shifts cannot cross over days, days cannot start before 00:00 or end after 23:59

How to split the time between two dates over daily columns

I am in much need of help please.
I have the table below.
It has about 300 rows and columns on the right for each day of the year starting 2015, ending 2019. I only entered a few columns here as an example.
What I need:
A formula to split the time (it can be hours or decimal days, it doesn't matter) between the two days on the left on the columns to the right.
In the rest of the days, which are not included in the period, I need a zero in those columns.
I manually entered the results I need so it can help you understand.
E.g.
On the first row:
The employee has spent
15 hours at destination in the first day of travel,
24 hours in the second day of travel
11:50 hours in the last day of travel.
All the rest of the columns to the right, which are not here, starting 1/4/2015 23:59 should give the result zero.
Thank You!!
Entry Date Exit Date 1/1/2015 23:59 1/2/2015 23:59 1/3/2015 23:59
1/1/15 9:00 1/3/15 11:50 15.00 24.00 11.50
As far as I can tell, it boils down to this
1.0 days 2.0 days 3.0 days 4.0 days
period=p in h/d.d p-(1-(so far)) p-(2-(so far)) p-(3-(so far)) 0
EDIT 2: I've come up with a formula.
NOTE:
This formula assumes existence of a column that specifies 0 hours of work between the "end date/time" column ("B") and first work hour ("D"), so you have it like this:
A B C D E F G H
1 Entry Date Exit Date ZERO 1/1/2015 23:59 1/2/2015 23:59 1/3/2015 23:59 1/4/2015 23:59 1/5/2015 23:59
2 1/1/15 9:00 1/3/2015 11:50 0 0.6243055556 1 0.49375 0 0.00
3
The extra column is there to avoid circular dependencies, since
we must "iteratively" accumulate the hours
The main formula for row 2 from column D being:
=MIN(D1-$A2,MIN(MAX(($B2-$A2) - SUM($C2:C2), 0),1))
Note: semicolons may be needed instead of commas in Excel as delimiters.
Note: the last digit in the formula depends on the unit. Here it is in days decimal. If hours, put 24.
In plain English, for a cell
Calculate sum of hours/days decimal in the range C to wherever - 1
Subtract result from the difference between start and end (total hours)
If less than 0, put 0 (MAX(x, 0))
If more than 1, put 1 (MIN(x, 1))
Choose between the result, or the difference between current date and start time, if it is smaller

Determine if time is before or after specific time

I have an Excel sheet with two date-time columns: Start Date and End Date. I need to calculate overtime by determining how many hours and minutes were worked before 08:00 and after 16:30.
Examples:
COLUMN A COLUMN B
1 2017/01/04 16:00 2017/01/04 18:00
2 2017/01/05 18:00 2017/01/05 21:00
3 2017/01/08 08:00 2017/01/08 17:00
4 2017/01/09 07:00 2017/01/09 09:00
I know the calculation for duration between times (=TEXT(B1-A1,"h:mm")), but I'm struggling to determine if a date-time is before 08:00 or after 16:30.
I've played around with TIMEVALUE("8:00:00"), TIMEVALUE("8:00:00 AM") and TIME(8,00,00) in my calculation, but the it did not work,
e.g. =IF(A1<=TIMEVALUE("8:00:00 AM"),"Yes","No") returns "No" even for A4 (2017/01/09 07:00)
I'm struggling with the calculation and the logic on this one. So far i'm using,
=IF(MOD(F2,1)<8/24,8/24-MOD(F2,1),0)+IF(MOD(G2,1)>16.5/24,MO‌​D(G2,1)-16.5/24,0)
Try this:
=IF(TIMEVALUE(A1)<=TIMEVALUE("8:00:00 AM"),"Yes","No")
Stick with treating time as time; only treat time as text when you have bad data (time as text is bad data) and then only enough to get it to be time as time.
To get the number of hours and minutes before 08:00 AM,
=MAX(0, TIME(8, 0, 0)-TIMEVALUE(TEXT(A2, "hh:mm;0;#")))
To get the number of hours and minutes after 16:30 AM,
=MAX(0, TIMEVALUE(TEXT(B2, "hh:mm;0;#"))-TIME(16, 30, 0))
In the following image you can see that I have left one group as true time and the forced the following group to be time as text¹. Both return correct results.
¹ Unless specifically formatted otherwise, numbers and dates/times are right-aligned in a cell; text is left-aligned.

Count num of values within range on every Nth cell

We have a data-set generated by an HR system of staff times, which isn't in the most helpful of formats.
We need to count the # of staff who start work before 10.00, and split those counts by week number (1-4) and day (Sun-Sat).
Every group of rows (1-4) is an individual.
Here's an example day's data:
Week Start
1 -
2 10:00
3 09.00
4 09.55
1 09:25
2 10.00
3 10:25
4 10.25
1 09:25
2 09.55
3 08:00
4 10.00
1 10:25
2 09.25
3 09:25
4 10.15
1 10.00
2 08:25
3 09.45
4 11:25
So I can count the occurence of start times before 10am on the entire column with:
=COUNTIFS(L5:L203,">=00:30",L5:L203,"<=10:00")
but to do separate counts for every 4th row (so sum all for ones on week 1, all on week 2, etc) is beyond me.
I tried the following after searching similar questions, but it didn't work:
=COUNTIFS((MOD(ROW(L5:L203),5)=0),">=00:30",(MOD(ROW(L5:L203),5)=0),"<=10:00")
Ideally I'd be able to put values into a table with a count for week 1 on Sunday, week 2 on Sunday, week 1 on Monday, and so on.
Any ideas?
To count the weeks use:
=COUNTIFs(B$2:B$21,"<=10:00",$A$2:$A$21,"=1")
=COUNTIFs(B$2:B$21,"<=10:00",$A$2:$A$21,"=2")
Changing =1, =2, =3, =4 for each weeks count. If column B is Monday and column C is Tuesday, you can drag the above formulas right across the row to get the weekly counts for other days.

Excel VBA - When 2 cells in a column are the same, add the 2 corrisponce number in the next column

I have three columns in my spreadsheet ID, Time and Height. What I want to do is run through the ID column and where the IDs match (Same ID occurs more than once in the list) sum the Height together for the earliest time (see example 2)
Example 1 (What I currently have)
ID Time Height
AB123 06:00 10
AD1234 10:00 10
AC12345 14:00 10
AC12345 06:00 10
AE123456 10:00 10
Example 2 (What I'm looking for)
ID Time Height
AB123 06:00 10
AD1234 10:00 10
AC12345 14:00 10
AC12345 06:00 20
AE123456 10:00 10
Within the sheet there may be 2, 2, 3 or 4 occurrence of the same ID number with multiple times.
I someone could help me with the VBA code for this I'd be very grateful.

Resources