So I just found out about ArrayFormula and am trying to convert my spreadsheet to utilize it, to be more efficient. Its worked wonderfully on all my columns except one, which is giving me trouble.
Currently, I have this formula in it (and copied to each cell):
=IF(C2="Immediate",
D2+1,
IF(C2="3 Day",
WORKDAY(D2,3,Holidays!$B$2:$B$11),
IF(C2="5 Day",
WORKDAY(D2,5,Holidays!$B$2:$B$11),
IF(ISBLANK(C2),
IFERROR(1/0)
)
)
)
)
It works wonderfully to calculate a date, based on a dropdown menu I have in another column. I cant figure out how to convert this to utilize ArrayFormula, as I get an error as soon as I add a second IF statement.
I can get the first statement to work with this formula:
=ARRAYFORMULA(IF(C2:C="Immediate",D2:D+1,))
But as soon as I try to add a second IF statement(such as with the formula below) I get an error.
How do I do this? I figure its probably simple but I cant figure it out!
Im trying to use a simpler formula to figure out where I am going wrong, and same thing will happen with the following formula so Im clearly doing something wrong!
=ARRAYFORMULA(IF(A1:A=1,"Hello",),IF(A1:A=2,"Goodbye",))
With only the first IF statement, it works. As soon as I add the second, I get #N/A
I know this is old but maybe try this formula:
={"Header_Cell_Name_Here";
ArrayFormula(
IFS(
$C$2:$C="","",
$C$2:$C="Immediate", $D$2:$D + 1,
$C$2:$C="3 Day", WORKDAY($D$2:$D,3,Holidays!$B$2:$B$11),
$C$2:$C="5 Day", WORKDAY($D$2:$D,5,Holidays!$B$2:$B$11)
)
)
}
IFS is a great alternative to IF. Rather than taking three arguments like you do with an IF statement:
IF(logical_expression, value_if_true, value_if_false)
an IFS statement can handle any number of conditions:
IFS(condition1, value1, [condition2, ...], [value2, ...])
Try this formula somewhere on row 1 of your sheet:
=ARRAYFORMULA(IF(A:A="",,IF(A:A=1,"Hello",IF(A:A=2,"Goodbye","Other Result"))))
you can use that formula
=ArrayFormula(IF(C2:C="",IFERROR(1/0),IF(C2:C="Immediate",D2:D+1,IF(C2:C="3 Day",WORKDAY(D2:D,3,Holidays!$B$2:$B$11),IF(C2:C="5 Day",WORKDAY(D2:D,5,Holidays!$B$2:$B$11),IF(ISBLANK(C2:C),IFERROR(1/0)))))))
here is an example
Your first formula, expanded to arrays, works perfectly well for me
=ARRAYFORMULA(IF(C2:C5="Immediate",
D2:D5+1,
IF(C2:C5="3 Day",
WORKDAY(D2:D5,3,Sheet2!$B$2:$B$11),
IF(C2:C5="5 Day",
WORKDAY(D2:D5,5,Sheet2!$B$2:$B$11),
IF(ISBLANK(C2:C5),
IFERROR(1/0)
)
)
)
)
)
This is the best arrayformula with multi if conditions I usually use
AND Operator
=Arrayformula(if(isblank(A2:A),,if((condition1) * (condition2) * (condition3),statement, if((condition1) * (condition2) * (condition3), statement, ))))
OR Operator
=Arrayformula(if(isblank(A2:A),,if((condition1) + (condition2) + (condition3),statement, if((condition1) + (condition2) + (condition3), statement, ))))
Example :
=Arrayformula(if(isblank(A2:A),,IF(((F2:F="Completed") * (J2:J <= 50)), $AT$3, IF(((F2:F="Completed") * (J2:J > 50) * (J2:J < 150)), $AT$4, IF(((F2:F="Completed") * (J2:J>150) * (J2:J < 250)), $AT$5, IF(((F2:F="Not_loaded") * (J2:J = 0)), $AT$6, 0))))))
Kindly note that braces are required to work correctly.
Related
I got this "table" (page raids) and want to do function formating for highlight duplicates (yellow).
Google Sheet
In this case there is match in 2 strings (dark blue):
Name1
Gunslinger
I already try functions VLOOKUP, Match, Filter, countifs and Quary (dont know how it works...) with Index function, but nothing seems work as I want ...
VLOOKUP and Match only gives first value.
Filter doesnt work on this strucker or I dont know how to use it in this case (I know how it works in normal table)
Can someone tell me what function conbination to use that can be put in Function formating ?
Formating for each row:
Example: =IF(B3>0;IF(B4<1490;TRUE;FALSE);FALSE)
ECT.
After some searching and testing, I came up with this:
=ArrayFormula(SUM(IFERROR(FIND(B2&B3;MID(CONCATENATE((TRANSPOSE($B$2:$I$33)));SEQUENCE(LEN(CONCATENATE((TRANSPOSE($B$2:$I$33))));1;1;1);len(B2&B3)))=1)*1))>1
Still need to make the functions more tidy (picture 2 and 3).
See if this is what you are looking for?
Conditional formatting with Custom formula in Range: A2:H:
=LAMBDA(NAME,OR(A1=NAME,A2=NAME,A3=NAME))("Gunslinger")
or do you means you want to highlight only duplicates?
If that is the case, you may try this formula:
=LAMBDA(DATARANGE,
LAMBDA(FLAT,
{{"Team","Duplicate"};{UNIQUE(FLAT),BYROW(UNIQUE(FLAT),LAMBDA(NAME,COUNTIF(FLAT,NAME)>1))}}
)(
QUERY(FLATTEN(
BYCOL(DATARANGE,LAMBDA(C,
BYROW(C,LAMBDA(R,
IF((ROW(R)+1)/4=INT((ROW(R)+1)/4),R,"")
))
))
),"SELECT Col1 WHERE Col1 IS NOT NULL",0)
)
)(A2:H)
This formula returns an array of unique Names with checking if there are Duplicates in the given datarange.
Combine this with the 1st formula should be able to highlight repeated data sets from your table.
Solution for 2 criteria matching:
The formula inside the image form the table of unique match results,
use that result with OR(), XLOOKUP(), OFFSET(), INDEX() as below for the final formula to put into the custom formula in conditional formatting.
=LAMBDA(RESULT,
LAMBDA(NAME,DUP,KEY,
LAMBDA(KEY_M2,KEY_M1,KEY_P1,
OR(
XLOOKUP(KEY_M2&"&&"&KEY_M1,NAME,DUP,FALSE),
XLOOKUP(KEY_M1&"&&"&KEY,NAME,DUP,FALSE),
XLOOKUP(KEY&"&&"&KEY_P1,NAME,DUP,FALSE)
)
)(IFERROR(OFFSET(KEY,-2,0),""),IFERROR(OFFSET(KEY,-1,0),""),IFERROR(OFFSET(KEY,1,0),""))
)(INDEX(RESULT,,1),INDEX(RESULT,,2),A2)
)(
LAMBDA(DATARANGE,
LAMBDA(FLATCLASS,
{{"Name","Duplicate"};{UNIQUE(FLATCLASS),BYROW(UNIQUE(FLATCLASS),LAMBDA(NAME,COUNTIF(FLATCLASS,NAME)>1))}}
)(
QUERY(FLATTEN(
BYCOL(DATARANGE,LAMBDA(C,
BYROW(C,LAMBDA(R,
IF((ROW(R)+1)/4=INT((ROW(R)+1)/4),IF(R="","",INDEX(C,ROW(R)-2)&"&&"&R),"")
))
))
),"SELECT Col1 WHERE Col1 IS NOT NULL",0)
)
)($A$2:$H)
)
I asked this before but I can't for the life of me find that question, so I just have to assume it dissolved into the ether.
I have this SUM function =SUM(QUERY($A$1:$B, "SELECT B WHERE A = '" & "s" & "'", 0)) that works just fine when used on one sheet, but not on another sheet in the same spreadsheet. In the other spreadsheet, it returns a zero rather than the total that it's supposed to. Through some experimenting, I've found that reducing the query search range seems to fix the problem, but that is unhelpful to me as the new range is smaller than what I need. If anyone knows anything about this or any possible fixes, some help would be super appreciated!
Here is a copy of the spreadsheet in question, all cells containing the formula are highlighted yellow: https://docs.google.com/spreadsheets/d/1bNmDYdUw-FU4wWTShV1cijtOt9l7McvktgAoDELbwQ8/edit?usp=sharing
If any more info is needed feel free to ask! Thank you!
Problem is in your K Column formula. The formula returning text instead of numeric number which causing trouble QUERY() formula. Change this formula =IF((E2*F2*H2)>0, Roundup(((E2/F2)+(E2/H2))/2, 3), "-") to
=IF((E2*F2*H2)>0, Roundup(((E2/F2)+(E2/H2))/2, 3), 0)
You can directly use avg() function to query formula to get average. Try-
=QUERY($B$2:$M, "SELECT avg(K) WHERE B = 's' label avg(K) ''", 0)
use:
="Average: "&AVERAGEIF(B2:B, "s", K2:K)
How can I get just the text within the quotes?
Below shows each line as a cell
a:3:{i:0;s:5:"hello";i:1;s:5:"sdfsf";i:2;s:6:"orange";}
a:4:{i:0;s:5:"hello";i:1;s:3:"How";i:2;s:3:"Are";i:3;s:3:"You";}
a:6:{i:0;s:5:"apple";i:1;s:6:"papaya";i:2;s:6:"Orange";i:3;s:4:"Pear";i:4;s:6:"Banana";i:5;s:9:"Starfruit";}
a:2:{i:0;s:5:"apple";i:1;s:0:"";}
Result that I would like is:
hello,sdfsf,orange
hello,How,Are,You
apple,papaya,Orange,Pear,Banana,Starfruit
apple,
You can use re:
import re
data = """a:3:{i:0;s:5:"hello";i:1;s:5:"sdfsf";i:2;s:6:"orange";}
a:4:{i:0;s:5:"hello";i:1;s:3:"How";i:2;s:3:"Are";i:3;s:3:"You";}
a:6:{i:0;s:5:"apple";i:1;s:6:"papaya";i:2;s:6:"Orange";i:3;s:4:"Pear";i:4;s:6:"Banana";i:5;s:9:"Starfruit";}
a:2:{i:0;s:5:"apple";i:1;s:0:"";}"""
quoted = re.compile('"[^"]*"')
for row in data.split("\n"):
print(",".join(value for value in quoted.findall(row)).replace('"', ""))
This prints:
hello,sdfsf,orange
hello,How,Are,You
apple,papaya,Orange,Pear,Banana,Starfruit
apple,
In case you want to do it using formula, you can use something like this:
=ArrayFormula(TEXTJOIN(",", 1, FILTER(TRANSPOSE(SPLIT(A1, CHAR(34))), IFNA(REGEXEXTRACT(TRANSPOSE(SPLIT(A1, CHAR(34))), "^[a-zA-Z ]*$"), FALSE())<>FALSE())))
Assuming your data is in separate rows.
try:
=ARRAYFORMULA(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(IFERROR(IF(REGEXMATCH(
SPLIT(REGEXREPLACE(REGEXREPLACE(A1:A, "(:"")", "♂♀"), "("";)", ",♂"), "♂"), "♀"),
SPLIT(REGEXREPLACE(REGEXREPLACE(A1:A, "(:"")", "♂♀"), "("";)", ",♂"), "♂"), ))),,9^9))),
", ♀,|,$|♀", ))
There are a lot of good answers here, but if you want a formula in one cell that gives you the trailing , after apple on the last line (as per your requested output), then you could use:
=arrayformula(regexreplace(flatten(split(textjoin(",",1,if(A1:A<>"",split(regexreplace(regexreplace(A1:A,"""""",char(6655))&char(9999),".\:.|[\:\{\}\;""]","|"),"|"),)),char(9999))),"^,|,$|"&char(6655)&"",))
Assumes your data is in Col A from row 1.
If not:
=arrayformula(regexreplace(flatten(split(textjoin(",",1,if(A1:A<>"",split(regexreplace(A1:A&char(9999),".\:.|[\:\{\}\;""]","|"),"|"),)),char(9999))),"^,|,$",))
Let's say your raw data were in A2:A. You could place the following in cell B2 of an otherwise empty range B2:B ...
=ArrayFormula( IF( A2:A="",, REGEXREPLACE( TRIM( TRANSPOSE( QUERY( TRANSPOSE( IF( REGEXMATCH( SPLIT( A2:A, CHAR(34)), ":|;|\{|\}"),, SPLIT( A2:A, CHAR(34))&",")),, COLUMNS( SPLIT( A2:A, CHAR(34)))))), "\s|[\s,]+$", "")))
This one formula will produce all results for the column. No dragging involved. (Interposed spacing in the formula as shown above is only for the sake of readability here on the site; none of the spaces are actually necessary to the functionality of the formula, and you may remove them if you like.)
If you'd like to pad comma-separated list entries with a space, remove this portion from the formula: \s|.
As to how it works, this is such a custom requirement that I don't think it will be of use to any future site visitors. So I encourage you to dig into it, take it apart and see what the parts do separately and cumulatively. And if you get stuck (if understand it is even important to you at all), feel free to ask any specific question you may have.
First of all, i'm not a powerful sheets user :)
I'm trying to use GOOGLEFINANCE to calculate amounts in multiple currencies.
I use this formula:
=IF($A2;
IF(
$C2:C;
$C2:C;
IF(
$D2:D;
$D2:D*INDEX(GoogleFinance("CURRENCY:USDUAH";"close";$A2);2;2);
$E2:E*INDEX(GoogleFinance("CURRENCY:EURUAH";"close";$A2);2;2)
));
0)
A-column contains dates,
C,D,E - amounts in 3 different currencies.
IFs are just to prioritize columns :)
The formula works well but i need to "extend" it each time i add row - to increment
$A2 -> $A3 to get rate for specified date.
I try to use ArrayFormula but it turns out it keeps reference to $A2 so i get same rate irrelevant from date specified in A-cells.
I have created sample sheet to illustrate:
https://docs.google.com/spreadsheets/d/1K2TbGIWl7JacYKiWgwwmJfelxJ-7fa9F9obp5XswW18/edit?usp=sharing
I have allowed editing by anyone, so if you decide to edit - please don't remove anything :) also you can drop your username in sticky row(above your proposed solution)
Is there a way to apply ArrayFormula to this to make it work?
Maybe you can provide more readable solution to nested IFs.
try:
=ARRAYFORMULA(IF(A2:A<>"";
IF(C2:C<>""; C2:C;
IF(D2:D<>""; VLOOKUP(TO_TEXT(A2:A);
TO_TEXT(QUERY(GOOGLEFINANCE("CURRENCY:USDUAH";
"close"; MIN(A:A); MAX(A:A)+1);
"offset 1 format Col1'dd.mm.yy'"; 0)); 2; 0)*1;
VLOOKUP(TO_TEXT(A2:A);
TO_TEXT(QUERY(GOOGLEFINANCE("CURRENCY:EURUAH";
"close"; MIN(A:A); MAX(A:A)+1);
"offset 1 format Col1'dd.mm.yy'"; 0)); 2; 0)*1)); ))
There is a new simpler and more flexible method now since the introduction of LAMBDA and its helper functions in Google Sheets in August 2022.
Assuming dates in A2:A, and amounts in UAH, USD, EUR in C2:C, D2:D, E2:E respectively, then the following formula will work, e.g. in cell F2:
=MAP(A2:A;C2:C;D2:D;E2:E;
LAMBDA(date;uah;usd;eur;
IFS(
uah;uah;
usd;usd*INDEX(GOOGLEFINANCE("currency:usduah";"price";date);2;2);
eur;eur*INDEX(GOOGLEFINANCE("currency:euruah";"price";date);2;2);
ISBLANK(date);)))
The trick here is that MAP(LAMBDA) calculates the specified formula for each row of the input array separately (effect similar to manually expanding the formula over the whole range), whereas ARRAYFORMULA passes the whole array as an argument to the formula (GOOGLEFINANCE is special and doesn't work intuitively with such input).
This general method with MAP(LAMBDA) can now be used to pass any arguments to GOOGLEFINANCE in a way one would otherwise expect to do with ARRAYFORMULA.
Try This One:
=arrayformula(
IF(query(arrayformula(if(A2:A="",False,True)),
"Select * where Col1=True"),
IF( $C2:C,
$C2:C,
IF( $D2:D,
$D2:D*INDEX(GoogleFinance("CURRENCY:USDUAH","close",$A2),2,2),
$E2:E*INDEX(GoogleFinance("CURRENCY:EURUAH","close",$A2),2,2))),0))
I would like to modify the following QUERY, or some formula variation that accomplishes the same result, to only be entered a single time at the top of the column and fill the cells below using ARRAYFORMULA
=IFERROR(QUERY(Items!$A$2:$T,"SELECT E,F,G,H,I,J,K,L,M,N,O,P,Q,R where A = '"&Estimate!A2&"' and B = '"&Estimate!B2&"' and C = '"&Estimate!C2&"' "&if(Estimate!D2<>"", "and D = '"&Estimate!D2&"'",)&" AND A is not null LIMIT 1", 0),"")
My formula is in Estimate!G2 of my spreadsheet.
this answer is pretty much correct, tho the exact formula would be:
=ARRAYFORMULA(IF(LEN(A2:A), VLOOKUP(A2:A&B2:B&C2:C&IF(LEN(D2:D), D2:D, "*"),
{Items!A2:A&Items!B2:B&Items!C2:C&Items!D2:D,Items!A2:T},
{6,7,8,9,10,11,12,13,14,15,16,17,18,19}, 0), ))
I think you'd have to use Vlookup, which isn't quite as convenient as Query. This is what I have so far, but it might need a bit more work to get exactly the same results as query in all cases (owing to the ORDER statement within the query):
=ArrayFormula(if(A2:A="","",vlookup(A2:A&B2:B&C2:C&if(D2:D="","*",D2:D),{Items!A2:A&Items!B2:B&Items!C2:C&Items!D2:D,Items!A2:T},{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21},false)))