I'm succesfully using the formula provided here in an answer here: Get date from week number in Google Sheets
So, I have:
=DATE(2023,1,1)-WEEKDAY(DATE(2023,1,1),3)+7*(WEEKDAY(DATE(2023,1,1),3)>3)+7*(C2-1)
Where C2 is a cell with the week number, and I'm getting the expected result 02/01/2023.
What do I need to change to get the result of 08/01/2023? - the last date of the week?
Thank you again for all of your help!
Part of my problem is probably that I can't work out what the bold parts refer to/mean/do:
=DATE(2023,1,1)-WEEKDAY(DATE(2023,1,1),3)+7*(WEEKDAY(DATE(2023,1,1),3)>3)+7*(C2-1)
To get a date that is 6 days later than the formula result, add 6 to that result, like this:
=6 + date(2023, 1, 1) - weekday(date(2023, 1, 1), 3) + 7 * (weekday(date(2023, 1, 1), 3) > 3) + 7 * (C2 - 1)
See Working with date and time values in Google Sheets.
Your formula looks unnecessarily complex. It is likely that there are much easier ways to get those dates, depending on your requirements.
you can try:
=LAMBDA(aix,MAX(FILTER(aix,WEEKNUM(aix,21)=C2)))(SEQUENCE(365,1,DATE(2023,1,1),1))
Related
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, )
I have a column with weeknumbers incrementing from 1 to 42.
Next to it I would like to have the corresponding monthnumbers from 1 to 12.
So e.g. next to week 1, 2, 3 it would be month 1.
How would I achieve this in google sheets?
Best
Florian
A week number may span a month end, so two different months for different days in the same week. ie
Not possible.
It's possible if you'll count concrete dates.
A1:
=ARRAYFORMULA( (ROW(INDIRECT("a1:a"&42)) - 1) * 7 + today())
adjust the date, change today() to your start date.
B1:
=FILTER(WEEKNUM(A1:A,1),A1:A<>"")
adjust week type if needed, change 1
C1:
=FILTER(MONTH(A1:A),A1:A<>"")
I have a production schedule where cells are filled with text:
Day 1, Day 2 etc.
And I'd like these cells to be associated with values elsewhere in the same sheet.
For example. Day 1 would be 4 (which corresponds to 4 hours).
Then I have to sum these cells/values (Day 1 = 4 + Day 2 = 6) to get a total for each row.
I can't seem to find a way to do all this using one formula. Is it even possible?
Feel free to check out the sheet.
=SUMPRODUCT(IFERROR(VLOOKUP(B2:L2,Formulas!A:B,2,0)))
I'm using Google sheets for data entry that auto-populates data from my website whenever someone submits to a form. The user's data imports into my sheet with a timestamp (column A).
Using the Arrayformula function, I'd like a column to autofill all the dates of a timestamp within that month. For example, if 1/5/2016 is entered as a timestamp, I'd like the formula to autofill in the dates 1/1/2016 - 1/31/2016.
Additionally, I'd like other months added in the Arrayformula column. For example, if both 1/5/2016 and 2/3/2016 are entered in column A, I'd like the formula to fill in the dates from 1/1/2016 - 2/29/2016.
I know I can manually write in the dates and drag them down the column, but I have a lot of sheets, and using an Arrayformula will save me a lot of time. I've tried a similar formula in column B, but it doesn't autofill in the date gaps. Is what I'm looking for possible?
Here's a copy of the editable spreadsheet I'm referring to: https://docs.google.com/a/flyingfx.com/spreadsheets/d/1Ka3cZfeXlIKfNzXwNCOWV15o74Bqp-4zaj_twC3v1KA/edit?usp=sharing
Short answer
Cell A1
1/1/2016
Cell A2
=ArrayFormula(ADD(A1,row(INDIRECT("A1:A"&30))))
Explanation
In Google Sheets dates are serialized numbers where integers are days and fractions are hours, minutes and so on. Once to have this in mind, the next is to find a useful construct.
INDIRECT(reference_string,use_A1_notation) is used to calculate a range of the desired size by given the height as a hardcoded constant, in this case 30. You should not worry about circular references in this construct.
ROW(reference) returns an array of consecutive numbers.
A1 is the starting date.
ADD(value1,value2). It's the same as using +. As the first argument is a scalar value and second argument is an array of values, it returns an array of the same size of the second argument.
ArrayFormula(array_formula) displays the values returned by array_formula
As A1 is a date, by default the returned values will be formatted as date too.
Increment by Month
If anyone wants to be able to increment by month, here's a way I've been able to accomplish that. Your solution #ptim got me on the right track, thanks.
Formula
Placed in B1
First_Month = 2020-11-01 [named range]
=ARRAYFORMULA(
IF(
ROW(A:A) = 1,
"Date",
IF(
LEN(A:A),
EDATE( First_Month, ROW( A:A ) -2 ),
""
)
)
)
Result
ID Month
1 2020-11-01
2 2020-12-01
3 2021-01-01
4 2021-02-01
5 2021-03-01
I have an alternative to the above, which allows you to edit only the first row, then add protection (as I like to do with the entire first row where I use this approach for other formulas):
=ARRAYFORMULA(
IF(
ROW(A1:A) = 1,
"Date",
IF(
ROW(A1:A) = 2,
DATE(2020, 1, 1),
DATE(2020, 1, 1) + (ROW(A1:A) - 2)
)
)
)
// pseudo code!
const START_DATE = 2020-01-01
if (currentRow == 1)
print "Date"
else if (currentRow == 2)
print START_DATE
else
print START_DATE + (currentRow - 2)
Notes:
the initial date is hard-coded (ensure that the two instances match!)
ROW(A1:1) returns the current row number, so the first if statement evaluates as "if this is Row 1, then render Date"
"if this is row 2, render the hard-coded date"
(nB: adding an integer to a date adds a day)
"else increment the date in A2 by the (adjusted) number of rows" (the minus two accounts for the two rows handled by the first two ifs (A1 and A2). Eg: in row 3, we want to add 1 to the date in row 2, so current:3 - 2 = 1.
Here's a live example (I added conditional formatting to even months to assist sanity checking that the last day of month is correct):
https://docs.google.com/spreadsheets/d/1seS00_w6kTazSNtrxTrGzuqzDpeG1VtFCKpiT_5C8QI/view#gid=0
Also - I find the following VScode extension handy for syntax highlighting Google Sheets formulas: https://github.com/leonidasIIV/vsc_sheets_formula_extension
The Row1 header trick is courtesy of Randy via https://www.tillerhq.com/what-are-your-favorite-google-spreadsheet-party-tricks/
nice. thanks.
To get the list length to adapt to the number of days in the selected month simply replace the static 30 by eomonth(A1;0)-A1. This accommodates for months with 31 days, and for February which can have either 28 or 29 days.
=ArrayFormula(ADD(A1,row(INDIRECT("A1:A"&eomonth(A1;0)-A1))))
Updated for 2022:
This can now be done pretty easily with the SEQUENCE function, it's also a bit more adaptable.
Below will list all of the days in columns but you can swap the first 2 values to place in rows instead:
=SEQUENCE(1,7,today()-7,1)
More specific to your example, below will take the date entered (via cell, formula, or named cell) and give you the full month in columns:
=SEQUENCE(1,day(EOMONTH("2016-1-5",0)),EOMONTH("2016-1-5",-1)+1,1)
I'm currently using a Google Spreadsheet at work to track employee hours. I had been using a formula to calculate hours, with hours worked expressed as a time (e.g. 6 and a half hours shows as 6:30). My boss has asked that I change the hours worked total to numbers (e.g. 6.5 instead of 6:30).
I had been using the following formula to calculate hours worked in time (where B is the out time and A is the in-time):
=if(isblank(B1),"", MINUS (B1,A1))
For calculating hours worked expressed in numbers, I have been trying to use the following formula:
=(IF(A1 <= B1, 0, 1)+B1 - A1) * 24
Now, this formula works when inputted into C1, but I'd like C1 to read as blank ("") until a value is inputted into B1, because otherwise it will show a value once I put something into A1.
Can anyone lend some insight?
You should be able to check that there are three values with COUNT(A1:C1).
=if(COUNT(A1:C1)<3, "", (IF(C1 <= B1, 0, 1)+B1 - A1) * 24)