Regexmatch variable cell instead of ?2$ - google-sheets

I got the following formula:
IF(ISBLANK(A1:A),,
IF(
REGEXMATCH(
TO_TEXT(A1:A),
"^(?i)[A-Z]+?2$"),
"double",
A1:A)))
Instead of only matching '2', I want it to match a specific cell. So that part should be something like: "^(?i)[A-Z]+? D1 $"),
How can I make this work?

You can use this simpler formula for all your mentioned cases
=INDEX(IF(REGEXMATCH(A3:A10&" ","\D+"&A1&" $|^"&A1&" $"),
"double",A3:A10))
(do adjust ranges and locale according to your needs)
(Also: please do NOT keep altering your original question as well as double posting)

Replace 2 with "&D1&".
IF(
REGEXMATCH(
TO_TEXT(A1:A),
"^(?i)[A-Z]+?"&D1&"$"),
"double",
A1:A)))

Related

Scalable Regexmatch formular

i need help with the following formula:
IF(REGEXMATCH(LOWER(B3), JOIN("|",Keywords!H$2:H$13)),"unqualified","qualified")
B3 is in this Case the String "I need help". My problem is that id like to use the Formula
IF(REGEXMATCH(LOWER(B3), JOIN("|",Keywords!H$2:H)),"unqualified","qualified")
so i dont always need to match the Row with the Keywords. Otherwise i have Spaces in the join formular and the results are always "unqualified".
Does anyone has an idea how i can rewrite this formula into a more "scalable Version"?
I hope everything i explained was understandable.
Try this out. You can remove the LOWER and make the regex case insensitive
=ARRAYFORMULA(
IF(ISBLANK(B3:B),,
IF(
REGEXMATCH(
B3:B,
"(?i)"&TEXTJOIN("|",TRUE,Keywords!H2:H13)),
"unqualified",
"qualified")))
I solved my problem with this formula:
IF(REGEXMATCH(LOWER(B3), JOIN("|",QUERY(G$2:G,"select G Where G is not null"))),"unqualified","qualified")

How can I extract the text within quotes in google sheets?

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.

Please help me with the Formula & ArrayFormula:

I want to return TRUE for blank cells until last value (check out the Required column)
I tried this formula: =AND($A2="" ,$A3:$A <> "") but it didn't work.
Question 1: How can I make 2nd argument i.e. $A3:$A <> "" return true if any one cell in the range $A3:$A is Not Null? Final Formula?
(I know my formula is wrong because it doesn't check every cell in the range mentioned if it is NULL or not, how can I make it check every cell?)
Question 2: ArrayFormula for the corresponding Formula.
(Please suggest if there's any better way to get the Formula & ArrayFromula along with the solution of the method I tried)
Here is the sheet link: https://docs.google.com/spreadsheets/d/1VF38MNcP1e4ieZY47QQq1zOwGYWAmuJ2k9A0WkGYeX0/edit?usp=sharing
EDIT:
I got the Formula: =IFNA(MATCH(FALSE,ArrayFormula(isblank(A2:A)),0),0)>1
For ArrayFormula I just tried wrapping it around but it didn't work: =ARRAYFORMULA(IFNA(MATCH(FALSE,ArrayFormula(isblank(A2:A)),0),0)>1)
I just need the ArrayFormula of this Formula & please tell me what's wrong in my ArrayFormula?
Thank you!
Try below formula.
=ArrayFormula(A2:A10="")
For full column
=ArrayFormula(A2:A="")
Edit: Then use below formula.
=ArrayFormula(INDEX(A:A,2):INDEX(A:A,MAX(IF(A:A<>"",ROW(A:A),0)))="")
try:
=INDEX(INDIRECT("A2:A"&MAX(IF(A2:A="",,ROW(A2:A))))="")
or:
=INDEX(INDIRECT("A2:A"&MAX((A2:A<>"")*ROW(A2:A)))="")
I suggest this simple formula:
=ArrayFormula(NOT(A2:A))
Since any value equates to TRUE and null equates to FALSE, wrapping the range in NOT will return the opposite.
ADDENDUM:
Given additional information from poster:
=ArrayFormula(IF((A2:A="")*(ROW(A2:A)<VLOOKUP(TRUE,SORT({A2:A<>"",ROW(A2:A)},2,0),2,FALSE)),TRUE,FALSE))

ArrayFormula with GoogleFinance dynamic date

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

How to use variable range in Google Sheets?

Currently I have such formula:
COUNTIFS(B3:B36,"16",E3:E36,"01")
Would it be possible to turn these ranges B3:B36 and E3:E36 into variables, like B'start_cell_value':B'stop_cell_value'.
The whole thing would look like:
=COUNTIFS(B'start_cell_value':B'stop_cell_value',"16",E'start_cell_value':E'stop_cell_value',"01")
start_cell_value and stop_cell_value are just some numbers stored in a separate cell. This would help, since changing numbers in those cells only would also change everything in the formula and that's exactly what I want.
I have tried to combine a numeric value from other cells with a letter to make a valid cell name but it doesn't seem to work or it just throws a reference error.
Any ideas would be appreciated.
If you have the start_cell_value in cell A1 and the stop_cell_value in A2 then try this formula:
=COUNTIFS(INDIRECT("B"&A1&":B"&A2),"16",INDIRECT("E"&A1&":E"&A2),"01")
with Named Ranges you can have it even exact:
=COUNTIFS(INDIRECT("B"&start_cell_value&":B"&stop_cell_value), "16",
INDIRECT("E"&start_cell_value&":E"&stop_cell_value), "01")
=COUNTIFS(INDIRECT("B"&A1&":B"&A2), "16",
INDIRECT("E"&A1&":E"&A2), "01")

Resources