ArrayFormula + simple if statement on Google Forms - google-sheets

I am building a worksheet that takes form-submitted data and runs a few calculations. I am having trouble autopopulating cells with simple if statements. I am wondering about how to use ArrayFormula with a statement like:
=IF(J2<I2+1,1,0)
Or, even more complicated, an IF statement and a VLOOKUP:
=IF(H2+K2=2,VLOOKUP(F2,'Event Info'!A2:D7,4,False),"Message")
Thanks!

These formulae may work as you want. The LEN(A2:A) section checks your column A and will only output if there is a timestamp value from the Form :
=ArrayFormula(IF(LEN(A2:A),IF(J2:J<I2:I+1,1,0),))
=ArrayFormula(IF(LEN(A2:A),IF(H2:H+K2:K=2,VLOOKUP(F2:F,'Event Info'!A2:D7,4,0),"Message"),))

Related

regexmatch doesn't seem to work with minifs in Google Sheets

I'm trying to find the min date for sub-tasks that are related to the same Task ID.
Because I want to leave the task min date cell blank if none of the sub-tasks have a date entered, I use the following formula:
=if(SUMPRODUCT(regexmatch($A18:$A,"^Sub-Task "&$B16&".[0-9]"),$F18:$F=$F16,G18:G<>"")<>0,minifs(G18:G,$A18:$A,regexmatch($A18:$A,"^Sub-Task "&$B16&".[0-9]"),$F18:$F,$F16,G18:G,"<>"),"")
This breaks downs as follows:
In the SUMPRODUCT function
I use regexmatch($A18:$A,"^Sub-Task "&$B16&".[0-9]*") to check that I only look at sub-tasks that have the same ID as the specific task "B16"
I use $F18:$F=$F16 to check that I only look for "Planned" dates, which is in "F16" instead of "Actual" dates
I use G18:G<>"" to check that I only look for date cells that aren't empty
If the sumproduct results in something, I then use the minifs() function to find the min value of the result.
IF the sumproduct results in nothing, I enter blank "" in the cell
The sumproduct seems to work perfectly well and gives me the results that I expect when I change values around, but the minifs function doesn't seem to work with regexmatch()
Is there a different syntax that has to be used in minifs functions?
try:
REGEXMATCH(A18:A&"", "^Sub-Task "&B16&".*")
inserting numeric value in regex will cause VALUE error
Figured it out, minifs can take regex directly, but only simple ones; it doesn't like characters like "^", and I was able to work around it for my needs.

Formula that will skip one column when calculating SUM() or similar functions

I'd like to run a =SUM(A1:G1), but always skip one column, regardless if it has value or not.
In this case, it should calculate A1+C1+E1+G1.
Is there another function I could append to SUM() or other similar functions as SUM in order to skip one column?
Thank you!
Using the following method you can calculate any number of alternate columns, without the need of manual +
Suppose your data is in second row onwards, use this formula
=SUMPRODUCT(A2:G2, MOD(COLUMN(A2:G2),2))
Simply a sumproduct of cell values and a array of {1,0,1,0,1...}
Another slight variation
=SUMPRODUCT(A2:G2*ISODD(COLUMN(A2:G2)))
But if the even columns contain letters instead of numbers this will give an error, so you can use instead
=SUMPRODUCT(N(+A1:G1)*ISODD(COLUMN(A1:G1)))
Comparing #AnilGoyal's answer, this works as well
=SUMPRODUCT(A1:G1,--ISODD(COLUMN(A1:G1)))
You can use:
=SUM(INDEX(A1:G1,N(IF(1,{1,3,5,7}))))
Or with Excel O365:
=SUM(INDEX(A1:G1,{1,3,5,7}))
A bit more of a general solution:
=SUMPRODUCT(MOD(COLUMN(A1:G1),2)*A1:G1)
Or with Excel O365:
=SUM(MOD(COLUMN(A1:G1),2)*A1:G1)
Or even:
=SUM(INDEX(1:1,SEQUENCE(4,,1,2)))
Since you included Google-Sheets, I'll throw in an option using QUERY():
=SUM(QUERY(TRANSPOSE(1:1),"Select * skipping 2"))
Maybe a bit more verbose, but very understandable IMO.
Consider something of the format:
=SUM(A1:G1)-INDEX(A1:G1,2)
The 2 in the formula means remove the 2nd item in the part of the row. (so the 999 is dropped)
So the formula =SUM(BZ10:ZZ10)-INDEX(BZ10:ZZ10,2) drops CA10 from the sum, etc.(a similar formula can be constructed for columns)
google sheets:
=INDEX(MMULT(N(A1:H3), 1*ISODD(SEQUENCE(COLUMNS(A:H)))))
=INDEX(IF(ISODD(COLUMN(A:H)), TRANSPOSE(MMULT(TRANSPOSE(
IFERROR(A1:H3*ISODD(COLUMN(A:H)), 0)), 1^ROW(A1:A3))), ))

How to make a relative reference in an array formula in Google Sheets

Here's the straightforward version of my question:
I want to change the following formula to an array formula...
Original formula (from cell J2):
=if(F4="VM:",G4,J1)
My attempt at converting to an array formula (in cell K1):
=arrayformula(if(row(A:A)=1,G3,if(F:F = "VM:",G:G,indirect("K"&row(A:A)-1))))
This works on rows where F = "VM:", but returns a #REF error on other rows. Function INDIRECT parameter 1 value is 'K0'. It is not a valid cell/range reference.
Thoughts on how to fix this?
The more complex version of my question. i.e. Why am I trying to do this?...
I have a weird spreadsheet with data that should really be in a Wiki.
I want to create filter views for each person so they can easily filter on only their own vendors. The original formula will work, but as more vendors are added, I'd like for the formula to automatically work for those rows as well.
If there's a better way to do this, I'm listening.
I don't exactly understand your needs, but If you want to autopopulate your formula, then you only need this code in desire column in row 4 (you can change this to any other - this will autofill down from this point):
=ArrayFormula(if(F4:F="VM:",G4:G,J1:J))
Is this what you are trying to get?
After clarification:
You need this code in J2 only:
=ArrayFormula(VLOOKUP(ROW(J2:J),
QUERY({F:G,ROW(G:G)},"select Col3,Col2 where Col1='VM:'",1)
,2,1)
)
Works for you?
maybe you just need to hide errors?
=IFERROR(ARRAYFORMULA(IF(ROW(A:A)=1,G3,IF(F:F = "VM:",G:G,INDIRECT("K"&ROW(A:A)-1)))),)

multiple if conditions nested with a concatenate - Google Sheets

I have a formula as follows which I'm using for a scheduling system within Google Sheets:
=IF(B2="","",(CONCATENATE($B$1&" "&B2&CHAR(10)&$C$1&" "&C2&CHAR(10)&$D$1&" "&D2&CHAR(10)&$E$1&" " &E2&CHAR(10)&$F$1&" " &F2&CHAR(10)&$G$1&" " &G2)))
currently my formula works b2 has a value inside it which is great, what I want however, is for the formula only to show if one value is inside either.
B2, C2, D2, E2, F2 or G2.
so if c2 has a value I want the formula to parse.
I've tried
=IF(B2,C2,E2) etc with no luck.
I've also tried:
=IF(OR(B2="",C2="") which parsed the formula but kept it visible even with no data.
Reason for this is that I pull these fields into a master schedule and I only want it to show when one of the fields is populated, if that makes sense? otherwise the schedule will look far to busy.
https://docs.google.com/spreadsheets/d/1KE3VOI43M4-QlWB0EZldCqR73d3RHDnRnUNlv1MqLMo/edit?usp=sharing
Document for you guys.
Cheers!
If your goal is to show a formula when any of a given range of cells is not empty (and display nothing if they are all empty), you can simplify your condition check by first joining all ranges, and then comparing to the empty string:
=IF(JOIN("", B2:G2)="", "", "Your Formula")
You need to use AND() instead of OR().
=IF(AND(B2="", C2=""), "", "Formula")
Also, although this makes the formulas longer, I do prefer to use a combination of IFERROR(), ISBLANK(), and NA(). I prefer this because a blank cell is not the same as one with an empty string in it. So my preferred way of writing the above would actually be:
=IFERROR(IF(AND(ISBLANK(B2), ISBLANK(C2)), NA(), "Formula"))
just another solution I came across which I thought was much better than my own and made the data above a little tidier.
=IF(A2<>"",CONCATENATE(IF(B2<>"",$B$1&": "&B2&CHAR(10),),
IF(C2<>"",$C$1&": "&C2&IF(OR(D2<>"",E2<>"",F2<>"",G2<>""),CHAR(10),),),
Essentially this will populate only whats selected instead of populating all the fields in headers and then populating the scheduled work stream.

Add title row with ARRAYFORMULA in Google Sheets

I watched a tutorial where the author uses an IF statement along with the ARRAYFORMULA function to add a title row to a column of data. Links are given to the docs; however, for an example of how to use ARRAYFORMULA see this answer.
An example can be seen below:
I was able to populate the C column by placing the following formula in C1:
=ARRAYFORMULA(if(row(A:A) = 1, "spent", B:B - A:A))
I'm confused about the syntax. I understand that X:X references the entire X column but I don't understand how it's being used to check if we're at cell A1 in one context and then being used to apply mass formulas in another context.
How does the above line work?
Can you illustrate with some examples?
It sounds to me that the information you learned led you to expect that row(A:A)=1 translates to row A1?
It works a little different than that, the syntax as your using it now, is basically saying if any row in A:A has a value of 1, then write "spent" else subtract B-A
My suggestion:
use a literal array to make your header, then use the if(arrayformula) to only populate rows with values, for aesthetics:
Example:
={"Spent";arrayformula(if(isnumber(A2:A),B2:B-A2:A,))}
Explanation:
The {} allow you to build a literal array, and using a semicolon instead of a comma allows you to stack your cells vertically, following that we check if there is a value in column A, if so, subtract A from B, else leave it blank.
why not just put the column title directly on the first row cell, and start the array formula from the 2nd row, using the A2:A, B2:B syntax?
If something does not have to be in a formula, better put it directly on the cell - simpler for others to understand what's going on, and the formula will be simpler.
If you put the array formula in line 2, and someone sorts the data, then the arrayformula will move. If it is in the header line, this is less likely to happen.
You can also use the IFS function to achieve a similar effect to the array,
=arrayformula(ifs(row(A1:A)=1,"Spent",A1:A="",,True,B1:B-A1:A)
Here the first condition checks the row number, and if it is row ONE, then inserts a Column Header.
The Second condition - A1:A="",, - ensures that blank lines are ignored.
The Third condition True (ELSE) performs the calculation.
This method also allows for different calculations to performed on different rows depending on requirements.

Resources