How can I reference the previous row in the =ARRAYFORMULA function? - google-sheets

I'm trying to create a unique ID in a Google Sheet using the =ARRAYFORMULA function. The ID should be made up by the first 3 letters of a supplier name in a column + the year(from a timestamp column) + the month(from a timestamp column) + a serial number starting with "01" and then resetting when the timestamp reaches a new month.
For the serial number to work, I need to reference the previous row. I'm not sure how to do that when using the =ARRAYFORMULA function. Any ideas will be greatly appreciated.
My current attempt is as follows:
={"Purchase Order ID";ARRAYFORMULA(IF(ISBLANK(E2:E),"",left(upper(SUBSTITUTE(I2:I," ","")),3)&TEXT(E2:E,"yy")&TEXT(E2:E,"mm")&TEXT(IF(MONTH(E2:E)=MONTH(E2:E),VALUE(RIGHT(D2,2))+1,1),"00")))}
Here is a screenshot of my Google Sheet.
The desired result should look like this:
TES220601 - where the date is: 29/06/2022
TES220602 - where the date is: 29/06/2022
TEB220701 - where the date is: 11/07/2022
ZNA220702 - where the date is: 11/07/2022
MAK220703 - where the date is: 13/07/2022
KHA220704 - where the date is: 16/07/2022
ICL220705 - where the date is: 18/07/2022
HERE is a link to my Google Sheet.

Try below array formula-
={"Purchase Order ID";Arrayformula(IF(E2:E="",,UPPER(LEFT(SUBSTITUTE(J2:J," ",""),3))&TEXT(E2:E,"YYMM")&COUNTIFS(Month(E2:E), Month(E2:E),I2:I,I2:I, ROW(E2:E), "<="&ROW(E2:E))))}

Formula for you
={"Purchase Order ID";ARRAYFORMULA(IF(ISBLANK(E2:E),"",left(upper(SUBSTITUTE(I2:I," ","")),3)&TEXT(E2:E,"yy")&TEXT(E2:E,"mm")&TEXT(COUNTIFS(TEXT(E2:E,"mm"),TEXT(E2:E,"mm"),ROW(E2:E),"<="&ROW(E2:E)),"00")))}

Related

Google Sheets - add all values until last key is found

I have a sheet where I need to add all the values from last interest date till current interest date. How can I do that ?
For example, here in the above sheet I need to calculate the interest charged on 01-Feb-2021 which is sum of $580.15 and $952.91 (in turn it is adding all interest values until last Interest keyword is found in 2nd column - which is $1533.06)
How do I calculate it automatically by looking at the previous and current Interest keywords in 2nd column.
add all values until last key is found
try:
=QUERY(B3:H, "select B,sum(H) where B is not null group by B label sum(H)''")
update:
=ARRAYFORMULA(SUM(INDIRECT(
ADDRESS(LARGE((B3:B="interest")*ROW(B3:B), 2)+1, 8)&":"&
ADDRESS( MAX((B3:B="interest")*ROW(B3:B)), 8))))

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)

Google Sheets date calculation

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

Return value of third column based on two column matches in Google Sheets

I'm trying to sort a long table so we can analyse the data easier. What kind of data do I have?
Column A: Product name
Column B: Date (start)
Column C: Date (end)
Column D: Price
What I need to do is make an overview of all the products and their price on a specific date so I can easily make a chart to show the price changes over time. I can do this via a pivot table, this works. But I also need it as a formula.
Now I'm using: =iferror(index($D$2:$D; match($G3; $A$2:$A; 0); match(H$2; $B$2:$B; 0))) but the problem is that it is only returning the value of one date and not for the other dates (I guess because it is looking for one value and not multiple values)
Is it possible with a combination of match( and index( function?
How can I solve this problem? I hope you guys can help me. Please find a link to a test spreadsheet here: https://docs.google.com/spreadsheets/d/1llvpWCF0VRQMPwDGtQZ0qBiuCIsQBqeJtr7KCq7PBvg/edit?usp=sharing
Thank you in advance!
It is because third argument of INDEX function must point to column number from first argument. In your case there is only one column - $D$2:$D and if third argument returns anything but one it result will be an error and formula returns empty string.
Instead use:
=iferror(index($D$2:$D; match(1;($G3=$A$2:$A)*(H$2=$B$2:$B); 0)))

Format Date and Time

In column A I have date and time.
In Column B I have this formula to split them:
={"COL B","COL C"; ArrayFormula(IF(NOT(ISBLANK(A2:A)), SPLIT(A2:A, " ")))}
My sheet is linked to a Google form.
Every time a new sheet is submitted, the new data looks like 44075 and 0.9756944444 and I always need to format as Date and the other one as time.
Is there any way that my formula will automatically format the splitted value in col b and c?
You might try this:
={"Date","Time"; ArrayFormula(IF(ISBLANK(A2:A),, {DATEVALUE(A2:A),TIMEVALUE(A2:A)}))}
or this:
={"Date","Time"; ArrayFormula(IF(ISBLANK(A2:A),, {INT(A2:A),MOD(A2:A,1)}))}
In either case, you'll want to do Format>Number Date for B and Format>Number>Time for C.
UPDATE:
Since you seem to want the formatting to appear a certain way without using the Format>Number option, this will output dates and times...
=ARRAYFORMULA({"Date","Time";IF(A2:A="",,TEXT(A2:A,{"m/d/yy","h:mm am/pm"}))})
I've tried a lot of formula and surrendered.
I've just added a script:
var date = ss.getRange('R2:R');
date.setNumberFormat("MM/dd/yyyy");
var Time = ss.getRange('S2:S');
Time.setNumberFormat("hh:mm:ss AM/PM");

Resources