Cannot use nested IF for CONCATENATE function - google-sheets

I have a column of data and need to use CONCATENATE to combine them as a string.
=CONCATENATE("{",char(34),0,char(34),":",B2,char(34),
IF(A3="Yes",CONCATENATE(",",char(34),1,char(34),":",B3),
IF(A4="Yes",CONCATENATE(",",char(34),2,char(34),":",B4),
IF(A5="Yes",CONCATENATE(",",char(34),1,char(34),":",B5),
IF(A6="Yes",CONCATENATE(",",char(34),1,char(34),":",B6))))),"}")
However, it only combines the first 2 data. Please help.
Demo sheet: https://docs.google.com/spreadsheets/d/1-xZr2SC2t2E5QKtmTD1kQFr-K8GgJjIHL83Wqr6xYF8/edit#gid=0

Try this:
="{"&JOIN(",",FILTER(CHAR(34)&SEQUENCE(5,1,0)&CHAR(34)&":"&B2:B6,A2:A6="Yes"))&"}"

Related

How to use IMPORTXML and SEQUENCE together in Google Sheet

=ARRAYFORMULA("https://www.amazon.com/product-reviews/B08C1W5N87/ref=cm_cr_arp_d_viewopt_rvwer?ie=UTF8&reviewerType=avp_only_reviews&sortBy=recent&pageNumber="&SEQUENCE(5,1,1,1))
I use the code above to have the links that I would like to scrap the data. There are 5 links.
=IMPORTXML(A6,"/html/body/div[1]/div[3]/div/div[1]/div/div[1]/div[5]/div[3]/div/div[*]/div/div/div[2]/a[1]/i")
I also use the formula above to scrap the data I want from the link. A6 refers to the first link the first formula creates.
What I would like to do is, if possible, I want to scrap the data from the 5 links and list them in a column.
=IMPORTXML(ARRAYFORMULA("https://www.amazon.com/product-reviews/B08C1W5N87/ref=cm_cr_arp_d_viewopt_rvwer?ie=UTF8&reviewerType=avp_only_reviews&sortBy=recent&pageNumber="&SEQUENCE(5,1,1,1)),"/html/body/div[1]/div[3]/div/div[1]/div/div[1]/div[5]/div[3]/div/div[*]/div/div/div[2]/a[1]/i")
The formula above did not work.
=ARRAYFORMULA(IMPORTXML("https://www.amazon.com/product-reviews/B08C1W5N87/ref=cm_cr_arp_d_viewopt_rvwer?ie=UTF8&reviewerType=avp_only_reviews&sortBy=recent&pageNumber="&SEQUENCE(5,1,1,1),"/html/body/div[1]/div[3]/div/div[1]/div/div[1]/div[5]/div[3]/div/div[*]/div/div/div[2]/a[1]/i"))
The formula above did not work as well. It always scraps the first link's data only.
Thank you for your help in advance.
keep in mind that IMPORTXML itself is a "type of arrayformula" so it is not supported under ARRAYFORMULA
in your case try to hardcode 5 IMPORTRANGE formulae into array {} like:
={IMPORTRANGE();
IMPORTRANGE();
IMPORTRANGE();
etc}
update
with new LAMBDA function its possible to do it in one go:
=INDEX(TRIM(FLATTEN(SPLIT(FLATTEN(BYCOL(
"https://www.amazon.com/product-reviews/B08C1W5N87/ref=cm_cr_arp_d_viewopt_rvwer?ie=UTF8&reviewerType=avp_only_reviews&sortBy=recent&pageNumber="&
SEQUENCE(1,5,1,1), LAMBDA(x, QUERY(IMPORTXML(x,
"/html/body/div[1]/div[3]/div/div[1]/div/div[1]/div[5]/div[3]/div/div[*]/div/div/div[2]/a[1]/i")&"×",,9^9)))), "×"))))

extracting values based on regex

I have a column which has urls, So below are the values of the column
https://www.example.com/jasja
https://www.example.com/jasdqw?new=exact
So what I want to extract is before the question mark and after the last slash
So here my output in the column should be
jasja
jasdqw
How can I get this using Regex
Tried =REGEXEXTRACT(C2:C16, SPLIT()), but don't know how to use this
Any help is appreciated
We can use REGEXEXTRACT with a capture group:
=REGEXEXTRACT(C2, "/([^/]+?)(?:\?|$)")
Here is a regex demo.
You could also try
=RegexExtract(A1,".*/(.*?)\?")

Splitting Text and Formatting it - Google Sheets

I have a log file with three fields, the first two are userIDs and the third is an item description. Can I use a single formula to Split the text, format the first 2 items, and leave the 3rd alone?
Sample Data:
<#!9812391203019>; <#!98120319283> ; Short Description
Formula Currently used:
=ARRAYFORMULA(REGEXEXTRACT(TRIM(SPLIT(A3,";")),"[0-9]+"))
This works to extract the userID from the unneeded in the first two columns but will only give me numbers for the third.
Previous Formula was within the REGEXEXTRACT but it left the unneeded "<#!" and ">" in the columns which I wanted to remove.
Any help and suggestions would be appreciated! Thanks in advance!
Does this work?
=Split(RegexReplace(A1,"[<#!>]",),"; ",0)
try:
=INDEX(IFERROR(REGEXREPLACE(TRIM(SPLIT(A1:A5, ";")), "[#!<>]", )))

How to extract text from cells with distinct

I tried different approaches to accomplish what I am looking for and it might not be possible with how I have formated my data but I will try to explain it to see if there is a way.
My origin of data looks like the following:
Case
HELP
100
HELP-01
HELP-02
101
HELP-01
102
103
HELP-03
What I want is to be able to extract the HELP-* into another column without duplicate values and one after another. The result I am looking for is from the above table been able to have this:
HELP
HELP-01
HELP-02
HELP-03
Is there a way to do this in Google Sheets?
Thank you,
Alternatively you can use:
=UNIQUE(QUERY(FLATTEN(B2:C),"where Col1 like 'HELP-%'"))
The QUERY() will now only return those values that start with 'HELP-' in the case you might have other string-values.
A littel more specific even, could be to use:
=UNIQUE(QUERY(FLATTEN(B2:C),"where Col1 matches 'HELP-\d+'"))
Where 'matches' will now use the regular expression to only return values that start with 'HELP-' but end with any 1+ digits.
Try this in Google Sheets
=sort(array_constrain(unique(flatten(B2:C)),counta(B2:C),1))

Countif with len in Google Spreadsheet

I have a column XXX like this :
XXX
A
Aruin
Avolyn
B
Batracia
Buna
...
I would like to count a cell only if the string in the cell has a length > 1.
How to do that?
I'm trying :
COUNTIF(XXX1:XXX30, LEN(...) > 1)
But what should I write instead of ... ?
Thank you in advance.
For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.
=COUNTIF(range,"=?*")
To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.
=SUMPRODUCT(LEN(XXX1:XXX30)>1)
If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:
=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))
Credit to #greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.
Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).
A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))
The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().
Here's a demo worksheet
Another approach is to use the QUERY function.
This way you can write a simple SQL like statement to achieve this.
For example:
=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")
To explain the MATCHES criteria:
It is a regex that matches every cell that contains 1 or more characters.
The . operator matches any character.
The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.
Here is a link to another SO question that describes this method.

Resources