Sheets: Array result not expanded - google-sheets

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

Related

Sum every n columns starting at the 1st column in the range

In Excel/Google Sheets I have found how to sum every N columns on websites such as https://exceljet.net/formula/fixed-value-every-n-columns, but the problem is, from what I can see is that it starts at N column each time. I need something that starts from column 1 and then counts every N columns. like the following:
I need to do this with a formula and not a script.
With Google-Sheets, try:
Formula in M2:
=SUM(QUERY(TRANSPOSE(A2:J2),"Skipping "&L2))
Or, a single dynamic array formula (without dragging):
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(10,1,1,0)))
Or, more dynamic:
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(COLUMNS(A2:J4),1,1,0)))
Note: The latter would also work in Excel with slight modifications.
Google sheets formula:
=SUM(FILTER(A2:J2, MOD(A2:J2, L2)=1))
then drag to other cells
or use this array version:
Array version:
=INDEX(TRANSPOSE(MMULT(A2:J4,TRANSPOSE(COLUMN(A2:J4)^0 *
N(MOD(COLUMN(A2:J4), L2:L4)=1)))), ,1)
If you want the cells that were added to be automatically highlighted.
Conditional formatting used on A2:J:
=MOD(COLUMN(), $L2)=1
In M2:
=SUMPRODUCT(A2:J2,N(MOD(SEQUENCE(,COLUMNS(A2:J2),0),L2)=0))
and copied down.
Try this formula on column M:
=SUM((sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2))+A2)
Here's the result on Column M.
Just to break down the code sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2) does the actual calculation with the number of intervals set on Column L but take note that I started at the 2nd column so the range here does not include the first column. The result from this is at the Column O highlighted red as you can see in the screenshot.
At the Column M is the actual solution where I only added the first column by using SUM on top of the previous formula.
I hope my explanation is clear.
Just copy/drag the formula down to each row and it should work.
Reference: How to Sum Every Nth Row or Column in Google Sheets Using SUMIF

Google sheets Combining Query with Today() [duplicate]

This question already has an answer here:
How to compare dates or date against today with query on google sheets?
(1 answer)
Closed 5 months ago.
I would like to use the today function in a query. Right now I have to manually change the date each morning, which is time consuming. The query is:
=QUERY(StageTracking!A:W, "SELECT C where A =date'2021-05-13'")
When I try
=QUERY(StageTracking!A:W, "SELECT C where A =today()")
I get a #VALUE error.
I know it's just a syntax thing I'm not catching but I have tried many variations on the line above.
Let me offer another (perhaps simpler) option, given what I can tell from your post info.
Add a header in the top cell of your results column and put the following formula into the second cell of that otherwise empty column:
=FILTER(StageTracking!C2:C,StageTracking!A2:A=TODAY())
ADDENDUM (after seeing the actual sheet):
This is an excellent case in point of why it is always most efficient and effective to share a link to a sheet, since your formula attempts as originally posted (and mine as posted above) would not work with your actual layout and goal.
I've added a new sheet ("Erik Help").
First, I un-merged Rows 2-8 and simply increased the height of Row 2. There was no reason to merge those rows; and merging nearly always causes issues, especially in ranges where formulas or reference ranges are involved.
Next, I deleted your original A2 formula (=QUERY(StageTracking!A1:W1000,"select C where A = '06/23/2021'",1)) and replaced it with the simple =StageTracking!C1, which accomplishes the same thing. Again, I'm not sure what led to the long formula, but it was unnecessary.
I then deleted all of your individual erroneous formulas from B2:K2 and replaced them with one formula in B2:
=FILTER(FILTER(StageTracking!E2:W,StageTracking!A2:A=TODAY()),ISODD(COLUMN(StageTracking!E1:W1)))
This formula first creates a FILTERed array of everything from E2:W where A2:A = TODAY(). Then a second FILTER is applied to bring in only the odd columns.
NOTE: currently, while the formula is working, you will see no results in E2:W because you don't have any data for TODAY in your StageTracking sheet yet. Once you add data for today's date, you will see the formula populate B2:K2. (Or, you can simply add -1 after TODAY() in the current formula if you want to see the results from "yesterday" temporarily, in order to be sure the formula is, in fact, working.)
Try this:
=QUERY(StageTracking!A1:W1000,"select C where A = '06/23/2021'",1)
or
=QUERY(StageTracking!A1:W1000,"select C where A = date '"&TEXT(TODAY(),"yyyy-mm-dd")&"'",1)
Take a few minutes to review the scalar functions supported in the QUERY() function.
https://developers.google.com/chart/interactive/docs/querylanguage#scalar_functions
You can use YEAR(), MONTH(), DAY() or NOW(). NOW() is a compete datestamp including time, so that would require more effort.

Stop formula if a certain cell has a date

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)

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.

Why can INDEX(...,COUNTA(...),..) find the last value of one array, but not another?

I'm learning basic =ARRAYFORMULA usage for a finance spreadsheet:
https://docs.google.com/spreadsheets/d/12cAGuUBzIo0LPbmtqWJZNFgjt94f1ybGoj6x2g0c2Y0/edit?usp=sharing
First, I used =GOOGLEFINANCE at B1 to pull up stock prices for a given date range in Column C
=GOOGLEFINANCE(A1,"price",DATE(2020,1,1),DATE(2020,5,30),"DAILY")
Then, I used simple arithmetic to multiply by number of shares at D2 and dragged the formulas down to get a nice column of values
=C2*20
Then, I used INDEX and COUNTA to pull out the last value of Column D at F3 === Great!
=INDEX(AAPL!D2:D,COUNTA(AAPL!D2:D),1)
Next, I turned my arithmetic formula into an ARRAYFORMULA at G2 === Cool!
=ARRAYFORMULA(C2:C103*20)
Of course, the problem with that ARRAYFORMULA is that I would have to manually change the array name in G2 every time the date range updated.
That is, instead of C2:C103, I would need to change the reference to C2:104 to get the columns to match === Rookie mistake!!!!!
So, I got smart with an ARRAYFORMULA containing a IF(ISBLANK(),...,...) at J2
=ARRAYFORMULA(IF(ISBLANK(B2:B),"",C2:C*20))
Column J stays fully populated with the correct values for any date range === !!!!!!!
But now the =INDEX(AAPL!J2:J,COUNTA(AAPL!J2:J),1) at L3 can't find the last value in Column J
Whaaat???
I've tried everything I can think of
It works if I use =INDEX(AAPL!J2:J104,COUNTA(AAPL!J2:J104),1) but that would defeat the purpose, since the reference J:J104 is going to change as the dates change
WHY???
I get the same results in both cells "L3" and "L5" when using:
=ARRAYFORMULA(IF(ISBLANK(B2:B),,C2:C*20))
Check that you are not returning a blank string ("") in your IF like: "=ARRAYFORMULA(IF(ISBLANK(B2:B),"",C2:C*20))" doing so will fill the cells up to the last row in the sheet with empty strings, thus when you use COUNTA(AAPL!J2:J),1) you get a lot more cells than you would expect, these extra cells are the ones you filled with blank strings in the array formula.
On the contrary when you limit the =INDEX(AAPL!J2:J104,COUNTA(AAPL!J2:J104),1) to cells with numbers only it doesn't mix strings and numbers in the calculation and you are naturally get the expected results.

Resources