Extracting person name from file name - google-sheets

I have a column of file names in the format {lastName}_{firstName}_{termInfo}_{Progress_Report/Transcript}_randomstringofcharacters.pdf
I would like to extract from this a variable that is lastName, firstName so that I can run a vlookup to match it to IDs. Is there an easy way to write a formula to do this?
Thanks!

try:
=JOIN(", ", ARRAY_CONSTRAIN(SPLIT(A1, "{_}"), 9^9, 2))
for array:
=IFERROR(BYROW(A1:A, LAMBDA(x, JOIN(", ", ARRAY_CONSTRAIN(SPLIT(x, "{_}"), 9^9, 2)))))

Option 01
=ArrayFormula(REGEXREPLACE(ARRAY_CONSTRAIN(SPLIT(A3,"_"),1,2), "\{|\}", ""))
Option 02
=ArrayFormula(BYROW(A2:A,
LAMBDA(rg, IFERROR(TEXTJOIN(", ",1,
REGEXREPLACE(ARRAY_CONSTRAIN(SPLIT(rg,"_"),1,2), "\{|\}", "")),""))))

Related

How to array unique in google spreadsheet?

I have data like this:
Cage Type
Open House, Open House
How to make it like this? so I can get a unique list.
Cage Type
Unique Cage
Open House, Open House
Open House
Use this
=TEXTJOIN(", ",1,UNIQUE(TRANSPOSE(SPLIT(A2, ", ",0))))
Arrayformula
=BYROW(A2:A, LAMBDA(r, IFERROR(TEXTJOIN(", ",1,UNIQUE(TRANSPOSE(SPLIT(r, ", ",0)))),"")))
try:
=INDEX(FLATTEN(REGEXREPLACE(TRIM(QUERY(QUERY(QUERY(SPLIT(UNIQUE(FLATTEN(
FILTER(ROW(A:A)&"​"&SPLIT(A:A, ", ", )&",", A:A<>""))), "​"),
"select max(Col2) where Col2<>',' group by Col2 pivot Col1"),
"offset 1", ),,9^9)), ",$", )))

Join range of row using arrayformula

I have a range of data on column A and B. In Column D , i have a reference for the shotID. I want to make a list for the artist involved for specific shotID.
In E2 i use this :
=JOIN( "," , FILTER($B$2:$B, $A$2:$A= D2))
then copy down to E3,E4. It works as i expected, but i want to do it using array formula. So only use single formula in E2 and that doesn't work that simple :
=arrayformula( JOIN( "," , FILTER($B$2:$B, $A$2:$A= D2:D4)) )
How can i do this ?
One more possibility that I learned from player0 and surprised he didn't suggest...
=ARRAYFORMULA(SPLIT(TRANSPOSE(SUBSTITUTE(TRIM(QUERY(QUERY(A2:B&{"|",CHAR(10)},"select MAX(Col2) where Col1<>'|' group by Col2 pivot Col1"),,100)),CHAR(10),",")),"| ",0))
take:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(SUBSTITUTE(
FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(SPLIT(
FLATTEN(A2:A&"×"&B2:B&","&"×"&B2:B), "×"),
"select Col1,max(Col2) where Col2 is not null group by Col1 pivot Col3"),
"offset 1", 0)),,9^9)), " ", "×", 1), "×")), ",$", ))
You could also try:
={unique(A2:A),arrayformula(transpose(substitute(trim(query(if(A2:A<>transpose(unique(A2:A)),,B2:B),,9^9))," ",", ")))}

search for a specific Column and then lookup the value of the matching row based off a name

I am trying to get a google sheet to search for a specific cell in a table. The headers change so it might be A6 one week and then A9 the other and so on.
Once it's found that row, I want it to search and pull all of that departments names and data for the column its matched with.
I am 23 sheets in and my heads hit a brick wall and I just can figure it out.
You can try:
=QUERY({A:B,INDEX(A:G,0,MATCH(D25,1:1,0))},"SELECT * WHERE Col2='" & LOWER(F25) & "'")
Note - you should remove unnecessary spaces. In sample data, they were in cells C1 and D25.
Try this:
=QUERY(
FILTER(
IFS(
TRIM(1:20) = "", 0,
ISNUMBER(1:20), 1:20,
True, LOWER(TRIM(1:20))
),
1:1 <> ""
),
"SELECT Col1, Col2, Col" & MATCH(TRIM(D25), ARRAYFORMULA(TRIM(1:1)),) & "
WHERE Col2 = '" & LOWER(F25) & "'",
1
)
You can use a combination of CHAR(MATCH...)) and Query formula to get this
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, "&CHAR(MATCH("Log 4",'Sheet Name'!A1:G1)+64)&" WHERE B='w'")
Above formula only works till column Z, but thanks to Kishkin's comment below, you can use it beyond Z like this:
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, `" & =REGEXEXTRACT(ADDRESS(1, MATCH("Log 4",'Sheet Name'!A1:G1), 4), "\D+") & "` WHERE B='w'")
You use SUBSTITUTE instead of REGEXTRACT too. You can refer to this Question.
the CHAR(MATCH...)) gets the column name of the desired Log
you can then use the column name to include that column in Query select statement
In the MATCH formula, you can also dynamically Match for a cell reference instead of specifying "Log 4" manually
Note: This is basically splitting the Query formula and concatenating it with another formula. So the &, ' and " symbols are really important
Sample Screenshot:

sum google sheet and break line in different date

I want to sum in a column but this sum need to break if is a different day
here a small example google sheets
Found this but formula '=SUMIF(ARRAYFORMULA(MONTH(Sheet1!A2:A)),1,Sheet1!B2:B)'
Do You mean something like this ?
={"Total"; ArrayFormula(if(len(A2:A),if(match(A2:A, A2:A, 0)=row(A2:A)-1,sumif(A2:A,A2:A,B2:B),),))}
JPV, I'm wondering if your solution would only work if there were exactly two entries per date.
My suggestion (in C2):
=ArrayFormula(IF(INDIRECT("A2:A"&ROWS(A:A)-1)="","",IF(A3:A=INDIRECT("A2:A"&ROWS(A:A)-1),"",VLOOKUP(INDIRECT("A2:A"&ROWS(A:A)-1),QUERY(A2:B,"Select A, SUM(B) Where A Is Not Null Group By A Order By A Desc"),2,FALSE))))
try:
=ARRAYFORMULA(IF(COUNTIFS(A2:A, A2:A, ROW(A2:A), "<="&ROW(A2:A))=1,
IFNA(VLOOKUP(A2:A, QUERY(A2:B,
"select A,sum(B) where B is not null group by A"), 2, 0)), ))

Custom Formula to Concatenate Multiple Rows If Condition Met

I'm having trouble writing a UDF for Sheets that would allow me to concatenate multiple rows of data into a single text field with a delimiter based on unique ID. I've seen examples of this for excel, but haven't been able to find a sheet's equivalent. Basically, I want to concatenate all values in B:B where B(i) = A(i) delimited by a comma or pipe or some other delimiter.
Basically, I want to concatenate all values in B:B where B(i) = A(i) in a single cell delimited by a comma or pipe or some other delimiter.
See if this formula helps
=textjoin(", ", 1, unique(filter(B:B, B:B=C:C)))
or, depending on your locale
=textjoin(", "; 1; unique(filter(B:B; B:B=C:C)))
If that doesn't help, please share a copy of your spreadsheet with editing rights.
to concatenate all values in B:B where B(i) = A(i) in a single cell delimited by a comma
=ARRAYFORMULA(REPT(INDIRECT("A1:A"&COUNTA(A1:A))&",",
QUERY(B:B, "select count(B) where B matches '"&
TEXTJOIN("|", 1, A:A)&"' group by B label count(B)''", 0)))
and to remove commas from the end you can do:
=ARRAYFORMULA(REGEXREPLACE(REPT(INDIRECT("A1:A"&COUNTA(A1:A))&",",
QUERY(B:B, "select count(B) where B matches '"&
TEXTJOIN("|", 1, A:A)&"' group by B label count(B)''", 0)), ",$", ))

Resources