Extract cell value to only between the third '/' and the fourth '/' - google-sheets

Values in column A
/teams/brazil/esporte-clube-vitoria/306/
/teams/brazil/gremio-esportivo-brasil/6205/
Expected values:
esporte-clube-vitoria
gremio-esportivo-brasil
Formula that I currently use but that generates errors when used with ARRAYFORMULA for various values:
=ARRAYFORMULA(IFERROR(TRIM(MID(SUBSTITUTE(A1:A,"/",REPT(" ",99)),299,99))))
Is there a more reliable formula for this job?

You can try the following formula
=ArrayFormula(REGEXREPLACE(R1:R,"/\w+/\w+/|[0-9]|/",""))
Formula that I currently use but that generates errors when used with ARRAYFORMULA for various values
Cannot test if this formula works for other values unless you share them.
One could also use
=ArrayFormula(INDEX(SPLIT(R2:R,"/"),,3))

Related

Array formula is not working with the combination of Vlookup and Indirect-Match?

I am trying to generate an arrayformula for the whole column but it does not work, when I use the same formula cell by cell, it generates correct value. Here is the formula for F1 cell:
=if(Iferror(vlookup($D1, INDIRECT("$"&"A"&MATCH(E1,$B:$B,0)+1&":$B"),2,false),"")=E1,"",Iferror(vlookup($D1, INDIRECT("$"&"A"&MATCH(E1,$B:$B,0)+1&":$B"),2,false),""))
I am trying to convert it into ArrayFormula like this and put it in F1:
=ARRAYFORMULA(if(Iferror(vlookup($D:$D, INDIRECT("$"&"A"&MATCH($E:$E,$B:$B,0)+1&":$B"),2,false),"")=$E:$E,"",Iferror(vlookup($D:$D, INDIRECT("$"&"A"&MATCH($E:$E,$B:$B,0)+1&":$B"),2,false),"")))
But this does not work and returns empty column, here is the sheet if you want to test it, you can find formula in column F:
https://docs.google.com/spreadsheets/d/13XLZvvdzK_mqr4Ous50cIEfernw2XrPJWvVgt1hFxtk/edit?usp=sharing
Please share your knowledge how to go about it as I am trying to learn formulas starting from basic level? Thank you.
when working with more than one condition, you can usually use FILTER for it. In this case, I used MAP to refer to both columns D and E, and used FILTER to narrow to the matches in A column, and then to those values that were further than the row of the MATCH of E value. Then, with INDEX I chose the first value of that resulting range.
=MAP(D:D,E:E,LAMBDA(d,e,IFERROR(IF(d="","",INDEX(FILTER(B:B,A:A=d,ROW(B:B)>MATCH(e,B:B,0)),1)))))
Unclear of the full scope but from your expected result scenario(in Column F) you seem to be pulling off second match(if any). well in that case try:
=BYROW(D:D,LAMBDA(dx,IF(dx="",,IFNA(FILTER(ARRAY_CONSTRAIN(FILTER(B:B,A:A=dx),2,1),{0;1})))))

Exclude Multiple Different Cells When Importing Data

I am trying to filter(query()) some specific columns into a spreadsheet where I do some automatic calculations. However, there are 8 or so specific strings that I don't need and clutter the calculations page. I have a list of these strings that I don't need but I can't seem to EXCLUDE these strings from the filter(query()) without creating a 15 line block of text.
What I've Tried:
=FILTER(QUERY(A:C,"select A,C"),QUERY(A:C,"select A")<>D2,D3,D4,D5)
=FILTER(QUERY(A:C,"select A, C"),QUERY(A:C,"select A")<>{D2,D3,D4,D5}) - I have also tried this one joining the text w/ a "," so that there is one value
=FILTER(QUERY(A:C,"select A, C"),QUERY(A:C,"select A")<>D2) - What is silly is THIS ONE VALUE works, but I cant add multiple values without adding 7 more conditions to the filter which would exclude the values that I need excluded, but I would have to change the formula manually and it would be monstrous when I keep adding strings to remove.
The goal is to be able to be able to add another string to a separate cell and have that be excluded as well.
Here is the google sheet: https://docs.google.com/spreadsheets/d/1u-Po1Oae4MTYU10o_-1Yu0s9Ras9JUn4-SFzTkmMldI/edit?usp=sharing
Suggestion
Perhaps you can try using REGEXMATCH so you could add multiple words to be matched but in the reverse way (via placing the REGEXMATCH in a NOT function) to FILTER your data more efficiently as seen below:
=FILTER(QUERY(Sheet1!A:C,"select A, C"),NOT(REGEXMATCH(Sheet1!A:A,"Value 7|Value 3|Value 10|Value 8")))
Alternatively, you could also reference the range of cells you want to exclude in the REGEXMATCH via JOIN function like:
=FILTER(QUERY(Sheet1!A:C,"select A, C"),NOT(REGEXMATCH(Sheet1!A:A,JOIN("|",D2:D5))))
[UPDATE]
If you're using an IMPORTRANGE in your actual sheet formula, then you would need to structure it like this sample. The REGEXMATCH formula also contains a range:
=FILTER(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/XXXXXX","Sheet1!A:C"),"select Col1, Col3"),NOT(REGEXMATCH(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/XXXXXX","Sheet1!A:C"),"select Col1"),"Value 7|Value 3|Value 10|Value 8")))
Demo
Sample Test
The referenced Sheet 1
References
REGEXMATCH
NOT
JOIN

Google Sheets - How to wrap OR function for Index, Text not working in formula

At the end of the day, in my Google Sheet I'm trying to filter a large data set by multiple criteria and sum a certain column. I have a mostly working formula but I'm running into a problem.
Here is an example that works:
=sum(INDEX(FILTER('Invoice Data'!H3:P,
'Invoice Data'!N3:N>=DATE(2022,1,1),
('Invoice Data'!H3:H="Arc")+('Invoice Data'!H3:H="Technical Products")
),0,9))
The ()+() in the second criteria works well as an OR condition. However, I want that criteria to be dynamic based on other information. So I've created the following formula that generates a text string as follows:
="('Invoice Data'!H3:H="&CHAR(34)&join(CHAR(34)&")+('Invoice Data'!H3:H="&CHAR(34),FILTER('Dropdown Menus'!D2:D34, A2='Dropdown Menus'!C2:C34))&CHAR(34)&")"
This successfully generates the text "('Invoice Data'!H3:H="Arc")+('Invoice Data'!H3:H="Technical Products")".
The problem is, when I put it into the original formula, it doesn't work.
=sum(INDEX(FILTER('Invoice Data'!H3:P,
'Invoice Data'!N3:N>=DATE(2022,1,1),
TO_TEXT("('Invoice Data'!H3:H="&CHAR(34)&join(CHAR(34)&")+('Invoice Data'!H3:H="&CHAR(34),FILTER('Dropdown Menus'!D2:D34, A2='Dropdown Menus'!C2:C34))&CHAR(34)&")")
),0,9))
I get the following error:
FILTER has mismatched range sizes. Expected row count: 27436. column count: 1. Actual row count: 1, column count: 1.
Any thoughts on what might be happening? I try to use "Indirect()" to have it be a cell reference, but that didn't work either.
You cannot make a text string become an executable formula that way.
What you can do is use the query() function and build the query statement dynamically.
For easier debugging, put the formula that builds the query statement text string in a cell of its own, and refer to that cell in the query(), like this:
=query('Invoice Data'!H3:P, S2, 0)
...where cell S2 contains your query statement.
instead of your OR try:
=SUM(INDEX(FILTER('Invoice Data'!H3:P,
'Invoice Data'!N3:N>=DATE(2022,1,1), REGEXMATCH(
'Invoice Data'!H3:H, "(?i)Arc|Technical Products")),,9))
where
"(?i)Arc|Technical Products"
can be dynamically referred as:
"(?i)"&TEXTJOIN("|", 1, FILTER('Dropdown Menus'!D2:D34, A2='Dropdown Menus'!C2:C34))

SUMIFS and/or QUERY inside ARRAYFORMULA

Google spreadsheet sample: https://docs.google.com/spreadsheets/d/1MdRjm5QmKY_vaah9c3GrvH6dDOBCQX_zvCubvN0akmk/edit?usp=sharing
Im trying to get the sum of all values for each ID. The values im trying to add up are found in the Source tab while the calculations are done in the Output. My desired values are based on 2 things: ID and Date. The Id is supposed to match and the Date is supposed to be February. I tried first just using a sumif with just matching ID and it worked using this formula: =ARRAYFORMULA(IF(A2:A="",, SUMIF(Source!A:A,A2:A,Source!B:B)))
But when I add the 2nd critera and use a sumifs function, it only outputs for the first id. Here is the sumifs formula I used: =ARRAYFORMULA(SUMIFS(Source!B2:B,Source!A2:A,A2:A,Source!C2:C,">="&DATE(2021,2,1),Source!C2:C,"<="&DATE(2021,2,28)))
I tried using query as some of the answers I found online suggested to use it but it also outputs the first data only, here is the query formula I used =ARRAYFORMULA(QUERY(Source!A2:C,"select sum(B) where A = '"&Output!A2:A&"' and C >= date '"&TEXT(DATEVALUE("2/1/2021"),"yyyy-mm-dd")&"' and C <= date '"&TEXT(DATEVALUE("2/28/2021"),"yyyy-mm-dd")&"' label sum(B) '' "))
I know this is possible by making a temporary query/filter where you only include desired dates and from there I can use SUMIF, but I will be needing to make a monthly total and making 12 of these calculated temporary filters/query would take up a lot of space since we have a lot of data so I want to avoid this option if possible. Is there a better fix to this situation?
Solved by Astrotia - =arrayformula(sumif(I3:I20&month(K3:K20), A2:A6&2, J3:J20))

ArrayFormula + simple if statement on Google Forms

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

Resources