how can we us this with Arrayformula - google-sheets

this formula need to be copy-pasted down everytime need to use array formula any idea how can be done
=if(and(ISNUMBER(SEARCH("agreed",F2))=true,F2<>"Disagreed"),1,0)

AND is not supported by ArrayFormula, that you need to use * or nested IF instead.
Besides, ISNUMBER returns a boolean such that =true is not needed.
=ArrayFormula(if(ISNUMBER(SEARCH("agreed",F2:F))*(F2:F<>"Disagreed"),1,0))

Related

I need ARRAYFORMULA() to use conditions in another row to decide what to calculate

Here is my formula in G5
=ARRAYFORMULA(IF(AND(J5:J17=true,H5:H17=false),E5:E17*F5:F17*1.075,IF(AND(J5:J17=true,H5:H17=TRUE),0,IF(and(J5:J17=false,H5:H17=false),E5:E17*F5:F17,IF(and(J5:J17=false,H5:H17=true),0)))))
This works if Cols H,I, and J are all false, however once I start setting anything in H,I,or J to true, the formula stops working.
Thanks for any help, Im really stumped on this one.
I think you can simplify your formula all the way down to:
=arrayformula(E5:E17*F5:F17*not(H5:H17)*if(J5:J17,1.075,1))
A few pointers:
What you were trying to achieve boils down to: 'on each row, give me the value of the cell in colE * the value of the cell in colF, multiplied by 1.075 if the cell in colJ is ticked, unless the cell in colH is ticked, in which case give me 0.
You don't need to evaluate tickboxes against TRUE/FALSE as they contain a TRUE/FALSE themselves (so the =TRUEs & =FALSEs in your formula are redundant)
AND/OR in arrays don't work the way you might initially want them to as they are aggregating functions (i.e. they accept arrays as input by design) and wrapping them in ARRAYFORMULA to try to make them evaluate the input arrays row-by-row or column-by-column doesn't work. Historically the answer to this problem has been to use Boolean algebra (where AND is * & OR is +, FALSE=0 and TRUE<>0) as I've done here which normally makes for the most compact representation, but more recently it's also been possible to use MAP to process arrays element-by-element (in which case AND/OR can still be used) as per one of the other answers
You only really need to use IF statements if you want to return values other than TRUE/FALSE (1/0) as a result of a logical evaluation (like your colJ where you want TRUE=1.075 & FALSE=1); otherwise you can omit them and just use Booleans.
use:
=ARRAYFORMULA(IF((J5:J17=true)*(H5:H17=false), E5:E17*F5:F17*1.075,
IF((J5:J17=true)*(H5:H17=TRUE), 0,
IF((J5:J17=false)*(H5:H17=false), E5:E17*F5:F17,
IF((J5:J17=false)*(H5:H17=true), 0)))))
You can try to do this with MAP:
=MAP(J5:J17,H5:H17,E5:E17,F5:F17,LAMBDA(j,h,e,f,
IF(AND(j=true,h=false),e*f*1.075,IF(AND(j=true,h=TRUE),0,IF(and(j=false,h=false),e*f,IF(and(j=false,h=true),0))))))

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

Google Sheet: Arrayforumla as sum_range argument in sumif throws error

Screenshot with example
I want to define the sum_range in an sumif-formula by using a range returned by an arrayformula but it gives me an error, not acknowledging it as a range. Using an arrayformula for the conditional range works however.
This works:
=sumif(
ARRAYFORMULA({B1;C3;D5}),TRUE,
A7:A9
)
This doesn't:
=sumif(
ARRAYFORMULA({B1;C3;D5}),TRUE,
ARRAYFORMULA({A1;B3;C5})
)
Am I doing something wrong here that I can't see or is it maybe just not possible? Maybe there's another smart way to do it..?
Why not use
=sumif(B1:B3, "TRUE", A1:A3)
or even
=sumproduct(B1:B3, A1:A3)
instead ?
If you really need to use inline arrays this should work
=sumproduct({B1, B2, B3}, {A1, A2, A3})
Bool to Number Casting
SUMPRODUCT will automatically cast Booleans to Numbers, so TRUE=1 and FALSE=0. If it doesn't, then the formula requires this to be a manual operation. You can leverage the N() formula to cast Booleans to Numbers manually.
Reference
N()
SUMPRODUCT()
you don't need any arrayformula to use the sumif as the sumif accepts array ranges:
=sumif(B:B; true; A:A)
ranges:*** ***
the thing is that you may not have a multidimensional array in your sum range column, only a single array, however, in your initial range you can have any multidimensional array:
=sumif(B1:B3;true;{A1:A3}) - error
=sumif({B1:B3};true;A1:A3) - works well
=sumif({B1:B3; B1:B3}; true; A1:A3) - works well as well

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

IsDate ArrayFormula

Have just noticed isDate does not work in arrayformula.
Case
Want to filter all values if dates:
Used the formula:
=FILTER(data,ISDATE(data))
Expected result:
8/28/2018
Got:
#N/A
Question
Why? Other checks work in filter (isNumber, isText, isErr).
Workarounds?
Please try:
=ARRAYFORMULA(ISDATE_STRICT(A1:A11))
The function is currently not documented.
🧐: ISDATE_STRICT wont let date&time format, dates only
Do not know the reason, still curious.
Workaround: =FILTER(data,IFERROR(DATEVALUE(data))) was found here
Note: Workaround will NOT work for dates formatted as:
dd.mm.yyyy
You may use a duck-typed workaround:
=FILTER(data,REGEXMATCH(MID(data,7,4),"20\d{2}"))
Will check if formatted date has a 20XX year string inside.
Now you can convert any formula to arrayformula:
=BYROW(A2:A12,LAMBDA(r,ISDATE(r)))
A workaround that could work depending on what you're trying to do as far as Arrayformula is concerned
=ARRAYFORUMLA(ISNUMBER(VALUE(data)))
VALUE can turn the time into a number
ISNUMBER checks if it's a number
ISNUMBER works fine within ARRAYFORMULA

Resources