Stop formula if a certain cell has a date - google-sheets

I ran into a problem with my Google sheet.
in the sheet Column "B" has an order date and Column "H" is counting days till today.
I want Column "H" to stop counting the day if Column"F" has a date.
Column "H" show day count till the date of column F
please see attached sample file.
Looking forward to your help

IF YOU WANT NOT TO USE YOUR FUNCTION WHEN DATE APPEARS IN COLUMN AND CONTINUE DOWN:
You should work with datevalue and iferror function (isdate does not work with arrayformula).
=ArrayFormula(
if(isblank(iferror(datevalue(B3:B23))),"your function","")
)
IF your formula is to count days passed since some date, try this:
={"Days passed";ArrayFormula(
if(isblank(iferror(datevalue(B4:B23))),today()-A4:A23,"")
)
}
IF YOU WANT THIS FORMULA TO GO FROM THE TOP AND STOP WHEN DATE APPEARS.
Core of the problem is how to check if data in this column is a date.
Then you have to use match formula to determine a row where the date is and stop arrayformula using array_constrain function.
First part (checking where is the data):
=match(FILTER(B3:B,IFERROR(DATEVALUE(B3:B))),B3:B,0)
(assuming that data is in B3:B)
We know that arrayformula should go only to 9th row of data.
So you should use =array_constrain(arrayformula(function you need);row to stop;1)
And as we have a match formula for determining a row to stop, whole formula should look like this:
=array_constrain(arrayformula(function you need);match(FILTER(B3:B,IFERROR(DATEVALUE(B3:B))),B3:B,0);1)

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,))

Google Sheet Increment Day Count with Interruptions

I have a google sheet that gives me a dynamic day increment. The formula I am using right now is this:
=IF(ISTEXT(A1),1,IF(WEEKDAY(B2)=7,,IF(WEEKDAY(B2)=1,,INDEX(FILTER($A$1:A2,$A$1:A2<>""),COUNT(FILTER($A$1:A2,$A$1:A2<>"")))+1)))
The first part (ISTEXT) checks the cell above to see if it has text...which happens to be the column header. If it does, we start the count at 1. After that, it will increment +1 as long as the date in column B is not a weekend (Saturday or Sunday). If it is, it will leave it blank. Then once it hits Monday again, it continues the count where it left off.
This gives me a dynamic way to count out a 20 work day schedule. I can plug in the start date and it will count out a 20 day work day schedule, skipping weekends. I am trying to add an additional mechanism to incorporate other interruptions to the work day schedule, such as holidays. I have a column (F) that I place notes in. I would like to have something like this incorporated in the original formula:
=if(F2="Holiday","H",<do the other stuff>)
Problem I am having is that everything I did in this original formula is based on empty spaces. Once an H gets placed in the field, it breaks the incrementing. I am thinking maybe I am overcomplicating this or doing something wrong, but hopefully someone can help me out here.
Example: Google Sheets
I duplicated the sheet (see tab JPV_HELP) and entered in B3
=sequence(eomonth(B2, 0)-B2, 1, B2+1, 1)
and in A2
=Arrayformula(if(C2:C<>"", regexreplace(C2:C, "[^A-Z]",), if( (weekday(B2:B) = 1)+(weekday(B2:B) = 7), ,countifs (weekday(B2:B), ">1", weekday(B2:B), "<7", C2:C, "", row(B2:B), "<="&row(B2:B)))))
If anything is entered in column C, the formula will extract the capital letters to output in column A.
See if that works for you?

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.

Sheets: Array result not expanded

I'm trying to use an array formula to calculate the 'days since last contact' in column U of my sheet. I started with:
=DATEDIF(V60, Today(), "D")
Which worked well and entered the number 1 in column U (I'm writing this on 12/7). Next I tried to turn this into an arrayformula which I've placed above the frozen header row in column U (#REF in screenshot). I'm trying:
=ARRAYFORMULA(if(ISBLANK(V2:V),"",DATEIF(V2, Today(), "D")))
The result that I'm looking for is in the following screenshot (assume today is 12/9):
That is, whenever a timestamp appears in column V, the array formula in the U cell next to it will keep a running tally of the number of days between the current day and the timestamp in U.
However the resulting #REF error reads:
Array result was not expanded because it would overwrite data in U3 . How can I get this working?
edit:
unfortunately that formula leads to the same "array not expanded" error:
edit2: following your directions I deleted the contents of u3 and placed the formula in u2:
I'm using an app script function on a timer to update PENDING to a timestamp using the apps script Date() function:
var u = updateRow(pendingRow,'3','last_contacted',new Date() )
This may account for differences in appearances after I cleared formatting from row V. However I looked at these and I can verify that they are date time objects.
Use array literals to join strings and formula.
U2:
=ARRAYFORMULA({"";"days since";IFERROR(IF(V4:V*1<>0,DATEDIF(V4:V,TODAY(),"D"),))})

Resources