I am trying to determine how to count the number of hours worked per hour.
Basically, I have collected data from all shifts over a one-year period, and I am trying to understand how many hours they work per hour. At times, there are multiple employees out at once.
So during a year period, I would like to understand how many estimated hours per hour of the day they worked. 1-24 hours Monday - Sunday. See example sheet.
What is the best approach to take? I'm a little stuck.
See example here: https://docs.google.com/spreadsheets/d/1RnqOM4jKphqluvI2TrYnzCP4EvF4ATBvJbU10VcNs1k/edit?usp=sharing
This is kind of hacky, but see if it checks out
=ARRAYFORMULA(
TRANSPOSE(
QUERY(
SPLIT(
FLATTEN(
IF(ISBLANK(C2:C),,
DATE(2022,1,1)+WEEKDAY(B2:B)&"|"&
IF(B2:B+TIME(SEQUENCE(1,24,0),0,0)>=B2:B+C2:C,
IF(D2:D+TIME(SEQUENCE(1,24,0),0,0)<D2:D+E2:E,
SEQUENCE(1,24,0),),))),
"|",TRUE,TRUE),
"select Col1, Count(Col1)
where Col2 is not null
group by Col1
pivot Col2
format Col1 'DDD'",0)))
Essentially, its checking if the date+time is greater than or equal to the start date + hours of the day and less than the end date + hours of the day. If its true, it'll return the start date with a pipe and that hour of the day. From there FLATTEN it and SPLIT by the pipe and run it through a QUERY.
The dates we're attaching are using the first Sunday of the year + the WEEKDAY value for the date so we can get clean text days in the proper order.
If this does work as expected and you'd like it broken down further, let me know. Change the IF(ISBLANK(C2:C) to IF(ISBLANK(C2:C5) to test it out on a smaller sample to verify the results.
Related
I have one workbook that has daily tracking of bidding dates and amounts and win day and amounts. In another workbook, I access that information to see the totals per day. Then play with that to see week/month/quarter and year performance. The problem I have is that I can not get my query searches to work in an array manner and have to drag the date driven formulas down 364 times for each column of information and all it's done is create a slow database...
=QUERY(importrange('source addresses'!$B$2,"bid tracker!$a$3:$x"),
"SELECT SUM (Col9)
WHERE Col8 = date '"&text(B5,"yyyy-mm-dd")&"'
label sum(Col9) '' ",0)
Col9 = amount of contract
Col8 = date of win
This formula produces a single data output for the sum of that days wins, I need it to array all 365 days to eliminate the other 364 of THESE formulas I am using due to my inexperience.
I have used arrayformula before query and after and every example I see doesn't seem to apply or work for me...
You need group by clause like group by Col8. Try-
=QUERY(importrange('source addresses'!$B$2,"bid tracker!$a$3:$x"),
"SELECT SUM (Col9)
WHERE Col8 <= date '"&text(B5,"yyyy-mm-dd")&"' AND Col8 >= date '"&text(B5-369,"yyyy-mm-dd")&
"' group by Col8 label sum(Col9) '' ",0)
I need a formula that will count the dates in column A and show how many of each month.
Example of the data in Column A
12/1/21
12/10/21
12/29/21
12/30/21
1/11/22
1/12/22
5/2/22
The returned data would be (or similar - I just need to know the total per month over the years)
12/21 - 4
1/22 - 2
5/22 - 2
and so on.
Here is what I go so far.
=ArrayFormula(month('tab name'!A2:A10))
but this list the months and not counts them.
use:
=INDEX(QUERY(TEXT(A1:A, "mmm e"),
"select Col1,count(Col1)
where Col1 <> 'Dec 1899'
group by Col1
label count(Col1)''"))
I have two spread sheet 1 is record for customer data and 1 is use for check the amount for particular month. I would to the calculation sum of the amount from first sheet to second sheet with filtering by month & year
First sheet will look something like this
In second sheets the only things that I would like to show is amount. Does not have to show the date anymore since filtering the amount by month & year
The Formula that failed is
=QUERY('CustomerData'!A:B, "select A, SUM(B) WHERE month(X)=month(date'2021-9-30')")
Try
=QUERY(CustomerData!A:B, "select sum(B) WHERE A>=DATE'2021-09-01' and A<=DATE'2021-09-30' ")
I wish to count events that occurred within a custom time interval : it could be within 24h, or within a week or 2-months span.
I am using google sheets: I can create a pivot table and group by month, however I'd like to explore insights using custom intervals (I'm looking for pattern in epilepsy).
As final result, I wanna have a table that, for each day, it is reported the number of frequencies within that interval.
Particularly, I wanna focus on the interval of 24h to count the number of events of epilepsy (known as cluster seizures).
And then, on custom days intervals to explore periodicity or trends - like each 48 hours, or each 15 or 30 days.
See a mockup of Google Sheet here:
https://docs.google.com/spreadsheets/d/1tCxYV5mUcq6vKm8-fL-0HUAOjcB9fipLCqPD2Znv-X0/edit#gid=1372548551
I tried this attempts:
find out how many events occurred in the last 30 days prior to the reported date:
= IFERROR(
QUERY(
A:E,
"SELECT COUNT(A)
WHERE
A IS NOT NULL AND
E = FALSE AND
A >= date '" &
TEXT(
A2-30,
"yyyy-MM-dd"
) &"' AND
A <= date '" &
TEXT(
A2,
"yyyy-MM-dd"
) &"'
LABEL COUNT(A) '' "), "N/A")
Then, dragging the cell, I get the column "# events in the prior 30 days".
It works but seems a bit messy - especially for updating the intervals.
I tried this other approach:
=query(B:E, "select B, count(E), -1+count(E) where E = FALSE group by B label B 'Date with Clusters', count(E) 'Cluster seizures '")
That produces the last table.
I like this approach better, but here I am just grouping by the same date, without possibility to have a custom interval.
As an example, I will have that two events will be counted within the same day, not withing the same 24h interval.
Could you tell a better approach to handle datetime differences, so to create binning and group by with custom intervals ?
Below an example:
on the left table, data in input; on the middle column, result of first approach; on the right table, results of second approach.
given the table:
in order to group stuff with QUERY we need to "fix" the A column in order to get a custom period. lets say we need to group events every 3 weeks (21 days). we take the lowest and highest date and create a sequence with all the dates in between.
=INDEX(ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A))))
then we use running total on it to get every date which is 21 days apart from the previous/next one. we could use simple SEQUENCE (for min>max) to create this array but with SEQUENCE we cant go "back in time" (for max>min) so we use MMULT and negative number
therefore, to start from a frame of the first date and create 3 weeks group by windows (eg. min>max) we use:
=ARRAYFORMULA({MIN(A2:A); MIN(A2:A)+MMULT(TRANSPOSE((
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))<=TRANSPOSE(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))*21); SiGN(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))})
and to get a reverse of it and start from frame of end date and create 3 weeks windows backwards (eg. max>min) we use:
=ARRAYFORMULA({MAX(A2:A); MAX(A2:A)+MMULT(TRANSPOSE((
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))<=TRANSPOSE(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))*-21); SiGN(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))})
at this stage, we can start fixing the A column via VLOOKUP and 4th argument set to 1 - approximate mode (instead of 0 - exact match mode) so forward in time will be:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A; SORT({MIN(A2:A); MIN(A2:A)+MMULT(TRANSPOSE((
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))<=TRANSPOSE(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))*21); SIGN(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))}); 1; 1)))
and backward in time shall be:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A; SORT({MAX(A2:A); MAX(A2:A)+MMULT(TRANSPOSE((
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))<=TRANSPOSE(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))*-21); SIGN(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))}); 1; 1)))
and now we just create a virtual array {} and pair fixed column A with column C and input it as range into QUERY
side note:
to put columns next to each other in english spreadsheets we use ,
to put columns next to each other in non-english spreadsheets we use \
=ARRAYFORMULA(QUERY({IFNA(VLOOKUP(A2:A; SORT({MIN(A2:A); MIN(A2:A)+MMULT(TRANSPOSE((
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))<=TRANSPOSE(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))*21); SIGN(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))}); 1; 1))\ C2:C};
"select Col1,count(Col1)
where Col2 = FALSE
group by Col1
order by count(Col1) desc
label count(Col1)''"))
and backwards in time:
=ARRAYFORMULA(QUERY({IFNA(VLOOKUP(A2:A; SORT({MAX(A2:A); MAX(A2:A)+MMULT(TRANSPOSE((
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))<=TRANSPOSE(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))*-21); SIGN(
ROW(INDIRECT(MIN(A2:A)&":"&MAX(A2:A)))))}); 1; 1))\ C2:C};
"select Col1,count(Col1)
where Col2 = FALSE
group by Col1
order by count(Col1) desc
label count(Col1)''"))
demo spreadsheet
I need to average the values that share the same ID and have been published in the same or previous months. I have to use ARRAYFORMULA due to the volume of rows.
This is an iteration of a question I asked last week: How to use AVERAGEIFS within ARRAYFORMULA, which I've tried to adapt for this, unsuccessfully.
As it can be a little confusing, I have created this file with dummy data. Although year and month were included in the ID at the beginning, I have split them into columns to make filtering easier.
Note that February average includes January values with the same ID, March includes January, February and March, etc. When the year changes, the average restarts. I suppose it could be done by comparing the values of the year (equals) and month (equals or lower), but I don't know how to insert the comparator into the last-day formula.
Thank you all for your time and effort.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B&C2:C; QUERY({A2:A&B2:B&C2:C\D2:D};
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
label avg(Col2)''"; 0); 2; 0)))
or if months does not matter use:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B; QUERY({A2:A&B2:B\D2:D};
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
label avg(Col2)''"; 0); 2; 0)))