I have a couple of questions I need for a semi-annual report:
I have a list of interns, each with their own start and end dates of service. I am looking to filter the list of those who worked within a given range of dates. I want any intern who has their term of service that overlaps with the range dates.
I am also looking to calculate how many weeks + months they worked within the same range of dates.
Here is the Spreadsheet.
I have tried your basic filter with date ranges, but I am not able to figure out the overlapping aspect of the list. For example, if the date range is 2021-2022, and an intern worked from 2020-2022, it would not filter it, as the start date is outside of the range.
Any help would be greatly appreciated!
This formula will work for all 3 columns:
=FILTER(
{
A2:A,
ARRAYFORMULA(
1+
TRUNC(ARRAYFORMULA(IF(C2:C<G2,C2:C,G2)-43101)/7)-
TRUNC(ARRAYFORMULA(IF(B2:B>F2,B2:B,F2)-43101)/7)
),
ARRAYFORMULA(
1+
DATEDIF(
ARRAYFORMULA(IF(B2:B>F2,B2:B,F2)),
ARRAYFORMULA(IF(C2:C<G2,C2:C,G2)),
"M"
)
)
},
ARRAYFORMULA((IF(C2:C>G2,G2,C2:C) - IF(B2:B<F2,F2,B2:B)) >0 )
)
For calculating the months the formula uses the DATEDIF function.
For calculating the weeks, I am choosing as reference an arbitrarily defined week zero starting on Monday, 2018-01-01 (day 43101 in the Network Time Protocol).
Link to Google Sheet
Check for Overlap
For a simple pull-down formula to check if each intern has any time overlapping the range, use the standard Overlap Formula:
Min(end1,end2)-Max(start1,start2)
which gives
=if(min(C2,G$2)>=max(B2,F$2),"Yes","No")
or for an array formula:
=ArrayFormula(lambda(start,end,if(if(end<G2,end,G2)>=if(start>F2,start,F2),"Yes","No"))
(filter(B2:B,A2:A<>""),filter(C2:C,A2:A<>"")))
Months
#Markus's approach is perfect, but for an alternative one could use:
=datedif(eomonth(max(B2,F$2),-1)+1,eomonth(min(C2,$G$2),0)+1,"M")
(for Jeremy as an example) in other words dial the start date back to the first of the month and the finish date forwards to the start of the next month and use Datedif to get the overlap in full months. The point of this is that it could be adapted for weeks as well.
With the lookup on names in column I2:
=datedif(eomonth(max(xlookup(I2,A$2:A$8,B$2:B$8),F$2),-1)+1,eomonth(min(xlookup(I2,A$2:A$8,C$2:C$8),$G$2),0)+1,"M")
or as an array formula:
=ArrayFormula(lambda(rNames,Names,start,end,datedif(eomonth(if(xlookup(rnames,Names,start)>F2,xlookup(rnames,Names,start),F2),-1)+1,eomonth(if(xlookup(rnames,Names,end)<G2,xlookup(rnames,Names,end),G2),0)+1,"M"))
(filter(I2:I,I2:I<>""),filter(A2:A,A2:A<>""),filter(B2:B,A2:A<>""),filter(C2:C,A2:A<>"")))
Weeks
You have a few options here.
(1) Having found the number of complete or partial months of overlap, just divide the number of days in those months by seven to get corresponding number of weeks:
=ArrayFormula(lambda(rNames,Names,start,end,quotient(datedif(eomonth(if(xlookup(rnames,Names,start)>F2,xlookup(rnames,Names,start),F2),-1)+1,eomonth(if(xlookup(rnames,Names,end)<G2,xlookup(rnames,Names,end),G2),0)+1,"D"),7))
(filter(I2:I,I2:I<>""),filter(A2:A,A2:A<>""),filter(B2:B,A2:A<>""),filter(C2:C,A2:A<>"")))
(2) Use the same logic as for months to get number of partial or complete working weeks of overlap:
=ArrayFormula(lambda(rNames,Names,start,end,quotient(datedif(if(xlookup(rnames,Names,start)>F2,xlookup(rnames,Names,start),F2)-weekday(if(xlookup(rnames,Names,start)>F2,xlookup(rnames,Names,start),F2)),if(xlookup(rnames,Names,end)<G2,xlookup(rnames,Names,end),G2)+7-weekday(if(xlookup(rnames,Names,end)<G2,xlookup(rnames,Names,end),G2),3),"D"),7))
(filter(I2:I,I2:I<>""),filter(A2:A,A2:A<>""),filter(B2:B,A2:A<>""),filter(C2:C,A2:A<>"")))
(3) Just get number of complete weeks of overlap by dividing number of days by 7:
=ArrayFormula(lambda(rNames,Names,start,end,quotient(datedif(if(xlookup(rnames,Names,start)>F2,xlookup(rnames,Names,start),F2),if(xlookup(rnames,Names,end)<G2,xlookup(rnames,Names,end),G2),"D"),7))
(filter(I2:I,I2:I<>""),filter(A2:A,A2:A<>""),filter(B2:B,A2:A<>""),filter(C2:C,A2:A<>"")))
I have a sheet with these columns:
A (Date): Range of dates for the year
B (Amount): An amount for an expense
D (Month): Name of each month in the year (e.g. June, July, etc)
I've tried this as suggested to work in other posts:
=SUMPRODUCT(B:B, ISDATE(A:A)*MONTH(A:A)=MONTH(D3&1))
I get the error Function MONTH parameter 1 expects number values. But 'Date' is a text and cannot be coerced to a number. with this.
If I remove the header, I just get a 0 for the sum for each month, which is incorrect.
How do I get this to work for each month the way my sheet is setup?
What the sheet currently looks like:
https://docs.google.com/spreadsheets/d/1_8DQTa9aXGjvd7twL6RZMcFyqxa4Sg7eVTcD2wDXH2A/edit?usp=sharing
Try this instead. Not sure where you got that other formula:
=SUMPRODUCT(B:B,TEXT(A:A,"mmmm")=D3)
use:
=ARRAYFORMULA(IFNA(VLOOKUP(MONTH(D3:D10&1),
QUERY(A2:B, "select month(A)+1,sum(B) group by month(A)"), 2, )))
Use this
=IF(D3="",,IFERROR(SUM(FILTER($B$2:$B,MONTH($A$2:$A&1)=MONTH(D3&1))),""))
I am looking to create a spreadsheet that my staff fill out, it then gives me a master sheet with all the data, then I import dynamically to my financial spreadsheet telling me the average cost of my client over the last 30 days.
I am looking to create an AVERAGE formula of the last 30 days when Date = Today (Monday) (I want the weekday Monday as that's when staff hand in invoices)
Hope this makes sense, it's really tough!
Here's a video of me explaining my desired outcome
https://www.loom.com/share/3a9cb75052b246d1af2ba2f9ce9180a7
I've followed several guides & can't figure it out.
=ArrayFormula(iferror(query(average(if(today() - weekday(today(),3)-30)))))
I expected $90 average and I just get blank
You could use this formula:
=AVERAGE(VLOOKUP(TODAY()-WEEKDAY(TODAY(),2)+1,A:H,2,FALSE),VLOOKUP(TODAY()-WEEKDAY(TODAY(),2)-6,A:H,2,FALSE),VLOOKUP(TODAY()-WEEKDAY(TODAY(),2)-13,A:H,2,FALSE),VLOOKUP(TODAY()-WEEKDAY(TODAY(),2)-20,A:H,2,FALSE))
To break it down in to its component parts, the AVERAGE is taken from VLOOKUP results:
VLOOKUP(TODAY()-WEEKDAY(TODAY(),2)+1,A:H,2,FALSE)
The VLOOKUP is looking for the last Monday from the current date:
TODAY()-WEEKDAY(TODAY(),2)+1
Then
TODAY()-WEEKDAY(TODAY(),2)-6
and so on...
When using on your sheet, you will have to specify the column you want to reference in your look up, for colunm B (brand1) use: A:H,2,FALSE), for colunm C (brand2) use: A:H,3,FALSE), for colunm d (brand3) use: A:H,4,FALSE) and so on...
=INDEX(QUERY({INDIRECT("A2:D"&ROW()-1)},
"select avg(Col2),avg(Col3),avg(Col4)
where Col1 <= date '"&TEXT(TODAY(), "yyyy-MM-dd")&"'
and Col1 >= date '"&TEXT(TODAY()-30, "yyyy-MM-dd")&"'"), 2, )