Google Sheets date calculation - google-sheets

Is there a way to take a date in one row and auto calculate another date in another column 10 days out?
ex: (column a) 12/11/20 -auto calculate the date 10 days from then
and put in (column d) 12/21/20.
So anytime I enter a date and need the 10 day out date it just auto calculates so I don't have to keep entering the date over and over again.

This is possible by using ARRAYFORMULA().
ARRAYFORMULA enables the display of values returned from an array formula into multiple rows and/or columns and the use of non-array functions with arrays.
Try this: =Arrayformula(TO_DATE(IF(A1:A="","", A1:A+10))).
Example:
Reference
Arrayformula()

Related

Populating columns with days based on a selection

I am trying to build a sleep tracker in Google Sheets (link). The idea is to select a year and a month from a drop-down list in cells A1 and A2, which would then populate columns based on the number of days in that month. I have tried different formulas that I found on stack overflow and elsewhere, but could not get them to work.
In short:
I am looking for a formula that will populate the columns with days of that month and a name of the day in a row bellow.
Looking for a way to summarize the time of sleep at the end of the each day, based on a ticked checkbox.
I am not sure how the year and month selectors should be formatted (as plain number or a date).
Is there a way to automatically insert check-boxes to the days of the month?
This is the formula that I have tried to adjust:
=INDEX({TEXT(SEQUENCE(1; DAY(EOMONTH(A2&"/"&A1;0)); A2&"/"&A1; 1); {"d"; "ddd"}); {"Total"; ""}})
But it returns with "Error In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Please note that ";" is used as an argument separator instead of "," (regional settings).
Thank you in advance!
I think that with a very small adaptation and date formatting you'll be able to easily do it. First with your selector in A2, you could set it as actual dates, but format them as mmmm:
Then, repeat the sequence in both rows starting in C2 and C3:
=SEQUENCE(1,DAY(EOMONTH(A2,0)),A2)
But formatting row 3 as ddd:
PS: yes, you can do row 3 with TEXT and INDEX. Choose your preferred one:
=INDEX(TEXT(SEQUENCE(1,DAY(EOMONTH(A2,0)),A2),"dddd"))
UPDATE with TEXT VALUES
Return to your previous A2 dropdown and try this, using MATCH to find the number of the month, and DATE to locate the correct beginning of the month in that year:
For row 2:
=SEQUENCE(1,DAY(EOMONTH(DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1),0)),
DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1))
For row 3:
=INDEX(TEXT(SEQUENCE(1,DAY(EOMONTH(DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1),0)),
DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1)),"dddd")
)

How to Auto Fill Date Column (with +30days) form Another Date Column in Google Sheet

I have 2 Columns like this
Where :
Start date is inputed by user
Finish Date is automatically filled with (Start Date + 30 days)
I have used this formula in Finish Date Column
=date(year(A:A),month(A:A),day(A:A)+30)
It works well, But the formula will work if we drag the blue box any number of cells down. I want to make it automatically filled after we input the start date. I also have read that we should use some script but I don't uderstand. Any solution? Thanks!
If you have start dates in A2:A, then array way to obtain the corresponding end date (30 days after) on each row is as follow in B2 cell.
ARRAYFORMULA(if(A2:A="","", A2:A+30))
Note: You can also put the condition like this: if(A2:A="",, A2:A+30) or just:
ARRAYFORMULA(if(LEN(A2:A),A2:A+30,))

In Google Sheets, how to check if Cell A (Date) is within the Date range of Cell B and C

I have a sheet with a timeline that shows a month per row in column A and an amount in USD next to that month in column B.
I want to be able to specify amounts in column G with a start and end date for that amount in columns E and F.
What I am trying to achieve is that the values in column B are automatically calculated by looking at the start and end dates specified in columns E and F and then taking the corresponding value from column G if the date in column A falls in between the date range specified in E and F.
I have found many suggestions for similar problems online but wasn't able to get any of them to work for my specific case. Any help is very welcome
You could do it as an array formula like this:
=ArrayFormula(mmult((text(indirect("A2:A"&count(A2:A)+1),"YYMM")>=text(TRANSPOSE(indirect("`E3:E"&count(E3:E)+2)),"YYMM"))*(text(indirect("A2:A"&count(A2:A)+1),"YYMM")<=text(transpose(indirect("F3:F"&count(F3:F)+2)),"YYMM"))*transpose(indirect("G3:G"&count(G3:G)+2)),(INDIRECT("G3:G"&count(G3:G)+2)+2)^0))
The idea is to develop a 2D array where the rows are the months and the columns are the amounts for matching time periods. Then use the standard Mmult method to get the row totals of the array.
Using indirect for the ranges makes the formula longer but using full-column references would be slow as it would result in a nearly 1000 X 1000 array for a default-sized sheet.
EDIT 1
Or shorter
=ArrayFormula(mmult((text(indirect("A2:A"&count(A2:A)+1),"YYMM")>=text(TRANSPOSE(indirect("E3:E"&count(E3:E)+2)),"YYMM"))
*(text(indirect("A2:A"&count(A2:A)+1),"YYMM")<=text(transpose(indirect("F3:F"&count(F3:F)+2)),"YYMM"))
,INDIRECT("G3:G"&count(G3:G)+2)))
because you can combine the row totals step with multiplication by column G.
EDIT 2
Alternatively you could just employ a much simpler pull-down formula using SUMIFS:
=ArrayFormula(sumifs(G$3:G,eomonth(E$3:E,-1)+1,"<="&A2,F$3:F,">="&A2))
This uses Eomonth to change all the start dates to the first of the month so they can be compared to the dates in column A correctly. The formula still has to be entered as an array formula because of the Eomonth calculation.
Note
The equivalent pull-down formula to the original array formulas above would be
=ArrayFormula(sumifs(G$3:G,text(E$3:E,"YYMM"),"<="&text(A2,"YYMM"),text(F$3:F,"YYMM"),">="&text(A2,"YYMM")))
but this gives zero for all rows - the reason for this is not obvious to me at time of writing.

Google sheets Average function is not calculating correctly

I'm using Google Sheets to create a financial record.
What i'm trying to do is create a formula that takes 3 columns in my data range in to consideration. The three columns are a date, a word and a number.
The first part of the formula will check that the date is the current month (not within 30 days, but the current month). The second part will check whether the word "Yes" is present in the second column, and if those two are true, then it will take the average of column 3 for all other rows that are also completely true.
Column C is Date
Column W is Word
Column Y is Number
I've tried a number of methods, the first one was to use a average IF function, where i used a filter to check the dates, and then the word Yes in the criterion. This resulted in a number, although it was incorrect, as the formula first gathered the sequence of Yes and No's, once it had the sequence it applied it to the third column but it started from my earliest entry (not my current month). This code is below.
So alternatively i tried another method. Which was using a query function. Although i'm stuck on how to compare the month of a date to the current today() month. This gives no results, even though the current month is 8, and the dates month is also 8. I've also inputted this code below.
=AVERAGEIF(filter(W8:W800,month(C8:C800)=month(today())),"Yes",Y8:Y800)
=query(query(A8:Z800,"select month(C)+1, W, Y where W ='Yes'",0),"select Col1, Col3, Col4 where Col1 ='"&month(today())&"'",1)
results explained in background
Your nesting is a bit off. If you're using FILTER, use plain AVERAGE instead of AVERAGEIF, and make sure you're grabbing the right column to aggregate. Lastly, don't forget to wrap in IFERROR to handle your empty case.
=IFERROR(AVERAGE(FILTER(Y8:Y800, MONTH(C8:C800)=MONTH(TODAY()), W8:W800="Yes")), 0)
if you have multiple criterions you need to use AVERAGEIFS instead of AVERAGEIF
=ARRAYFORMULA(AVERAGEIFS(C2:C, B2:B, "yes", MONTH(A2:A), MONTH(TODAY())))

sumif (data was entered on a monday)

I'm trying to have a function in Google Sheets that adds up values from a range if the were entered on a Monday. This is what I have right now, but it adds up to 0 all the time:
=sumif(B6:B20, WEEKDAY(2),C7)
Can someone tell me how to determine what day of the week a number cell was added on, and then add up all the numbers added on that day so I can put the sum in a different cell? (For example, the numbers in the range were added on various days of the week, and I want to add up all the numbers that were added on Monday)
Assuming column B is the column to sum and column C has the dates try:
=sumproduct(weekday(C2:C) = 2,B2:B)

Resources