Trying to combine range E4:I into J4:J with the Array Formula of:
=ArrayFormula( regexreplace( regexreplace( transpose( trim( query( transpose( regexreplace( trim( E4:I ) , " " , "~" ) ) ,, 9^99 ) ) ) , " " , ", " ) , "~" , " " ) )
This formula works well but I want to exclude duplicates in each row.
Here is a link to the sheet. Link
You can try this modified formula from a similar post:
=INDEX(
REGEXREPLACE(SORT(
SPLIT(
TRANSPOSE(QUERY(
QUERY(
UNIQUE(
SPLIT(
FLATTEN(
ROW(E2:I11) & "♦♥" & E2:I11
), "♥"
) & ", "
),
"SELECT MAX(Col2)
WHERE Col2 IS NOT NULL
GROUP BY Col2
PIVOT Col1",
),,99
)),"♦"
), 1, TRUE),
"^(?:,\s*)+|(?:,\s*)+$|(,\s)\s*(?:,\s*)*",
"$1"
),,2)
Output:
Note:
Output is automatically sorted alphabetically
You can change E2:I11 to E2:I but it will be slower than limiting your range. If you have a column that can identify until what row is populated, add an IF statement and limit your formula to only process those rows.
Reference:
https://stackoverflow.com/a/67837006/17842569
Related
I'm trying to count longest and current streak from null or 1 values in google sheets.
It's going to be used in Data Studio, but I have to make calculation in Sheets.
I've tried a sultion from below post, but it's nor working for me and also I have null values not 0, and it has to stay this way (rows in sheet are being appended from google forms form, where I check whether I did a habit or not).
Google Sheets - How to count streaks of non-zero numbers on one column
Please help if you can, thanks before
Here is the spreadsheet with some example data
https://docs.google.com/spreadsheets/d/1GaaEJ24ERulPftYAILOuokY929HInkh-SjAJUEvrW5M/edit?usp=sharing
values to visualize in streaks
Use this to get the longest streak in data:
=arrayformula(
if(
len(join(""; Data!A1:A));
max( len( split(
concatenate( left(isblank(Data!A1:A)) );
"T"
) ) );
"no streak"
)
)
And this to get the last streak in the data:
=+sort(
if(
len(join(""; Data!A1:A));
len( transpose( split(
concatenate( left(isblank(Data!A1:A)) );
"T"
) ) );
"no streak"
);
sequence( rows(
transpose( split(
concatenate( left(isblank(Data!A1:A)) );
"T"
) )
) );
false
)
See your sample spreadsheet.
longest:
=INDEX(COLUMNS(SPLIT(FLATTEN(SPLIT(TRIM(QUERY(IF(A1:A=""; 0; "×");;9^9)); " 0 "; )); " ")))
all:
=INDEX(QUERY(LEN(SUBSTITUTE(FLATTEN(TRIM(SPLIT(QUERY(
IF(A1:A=""; "×"; "¤");;9^9); "×"; ))); " "; ));
"where Col1 <> 0"))
last:
=INDEX(QUERY(SORT(LEN(SUBSTITUTE(FLATTEN(TRIM(SPLIT(QUERY(
IF(A1:A=""; "×"; "¤");;9^9); "×"; ))); " "; ));
SEQUENCE(ROWS(A1:A)-COUNTA(A1:A)); 0); "where Col1 <> 0 limit 1"; ))
I am looking to split, and flatten, with an array formula, and keep the correct corresponding Reference Number, assigned to multiple rows of flattened data.
Column A: Reference Number
Column B: ID (CSV)
Column C: TEMP ID (CSV)
Current Format
| A | B | C |
|111|001 002 | |
|222|004 005 006 008| |
|333|007 |T001 T006 T002|
|888| |T005 T004 T008|
|444| |T007 |
Expected Results
| A | B | C |
|111|001| |
|111|006| |
|222|004| |
|222|005| |
|222|006| |
|222|008| |
|333|007| |
|333| |T001|
|333| |T006|
|333| |T002|
|888| |T005|
|888| |T004|
|888| |T008|
|444| |T007|
Here is another post which is similar to what I am looking to accomplish.
(The only difference is in this post, the OP only had 2 columns.)
Here is the formula that I'm using (Not working perfectly):
=ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT('Form Responses'!C2:D, " "))="",,
'Form Responses'!B2:B&"×"&SPLIT('Form Responses'!C2:D, " "))), "×"), "where Col2 is not null")))
What am I doing wrong?
Here is my sheet.
Use this:
=arrayformula(
regexreplace(
text(
split(
query(
flatten( iferror( 'Form Responses'!B2:B & "µ" & iferror(split('Form Responses'!C2:C, " ")) & "µ" & iferror(split('Form Responses'!D2:D, " ")) ) ),
"where Col1 is not null and not Col1 ends with 'µµ' ",
0
),
"µ", false, false
),
"000"
),
"000", ""
)
)
Note that this formula will produce a row that looks like this:
Reference
#ID
Temp ID
333
007
T001
I.e., source data rows that have both an ID and a Temp ID will share a reference number. To make these IDs go to their own rows, use this:
=arrayformula(
regexreplace(
text(
split(
{
query(
flatten( iferror( 'Form Responses'!B2:B & "µ" & iferror(split('Form Responses'!C2:C, " ")) & "µ" ) ),
"where Col1 is not null and not Col1 ends with 'µµ' ",
0
);
query(
flatten( iferror( 'Form Responses'!B2:B & "µµ" & iferror(split('Form Responses'!D2:D, " ")) ) ),
"where Col1 is not null and not Col1 ends with 'µ' ",
0
)
},
"µ", false, false
),
"000"
),
"000", ""
)
)
The result table will have all the ID rows first, followed by the Temp ID rows.
I have a list of reservations with a startDate, endDate and itemNumber. Now i want to have a list of all the dates between those dates and the itemnumber next to it. I have this working for 1 reservation, but i can't get it to work with multiple reservations in one arrayformula.
I have a sample sheet (edit rights) with my formula's and the expected outcome.
Someone here that can help me out?
Sample sheet
Two Formula Version:
Item Column (Assuming K):
=ArrayFormula(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")))
or
=ArrayFormula(
IFNA(
HLOOKUP(
"StartDate",
Reservation!B:B,
MATCH(
FILTER(K3:K,K3:K>0),
Reservation!D2:D,
0
)+1,
0
)+IFNA(
ROW(K3:K)-2-MATCH(K3:K,K3:K,0)
)
)
)
This generates the list of Items based on the difference between the dates.
Date Column (Assuming J):
=ArrayFormula(IFNA(HLOOKUP("StartDate",Reservation!B:B,MATCH(FILTER(K3:K,K3:K>0),Reservation!D2:D,0)+1,0)+IFNA(ROW(K3:K)-2-MATCH(K3:K,K3:K,0))))
or
=ArrayFormula(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
)
)
Based on the Item, get its offset in the Item column (above) and add it to the Start Date for the corresponding item.
Single Formula Version:
Looks very messy, but is mostly just substituting K's into second formula above.
=ArrayFormula(
{
IFNA(HLOOKUP("StartDate",Reservation!B:B,MATCH(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")),Reservation!D2:D,0)+1,0)+IFNA(SEQUENCE(COUNTA(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),","))))-MATCH(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")),TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")),0))),
TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),","))
})
Or if you prefer:
=ArrayFormula(
{
IFNA(
HLOOKUP(
"StartDate",
Reservation!B:B,
MATCH(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
),
Reservation!D2:D,0
)+1,
0
)+IFNA(
SEQUENCE(
COUNTA(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
)
)
)-MATCH(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
),
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
),
0
)
)
),
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
)
})
(Due to my organization policies I cannot share a sample sheet.)
I have two sheets with data like so:
Sheet1
Sheet2
Now, in Sheet1, in column C, I am looking for an ARRAYFORMULA that will look up the value in Sheet1!A:A by matching the substring in Sheet2!A:A after removing the spaces from Sheet2!A:A and then returning the value from the row in Sheet2!B:B.
I came up with a non-ARRAYFORMULA formula to get the data per-row (in Sheet1!C:C below). But my real data-sets have thousands of rows and I don't want to have to copy/paste a formula into each one.
Each row has a formula that looks like so:
=TEXTJOIN(
", "
, TRUE
, IFNA(
FILTER(
Sheet2!B:B
, Sheet2!B:B <> ""
, Sheet2!A:A <> ""
, NOT(
ISERROR(
SEARCH(
REGEXREPLACE(Sheet2!A:A, " ", "")
, A2
)
)
)
)
, "not found"
)
)
I tried to convert this to an ARRAYFORMULA in Sheet1!B2 but it doesn't yield the expected result. The formula is:
=ArrayFormula(
TEXTJOIN(
", "
, TRUE
, IFNA(
FILTER(
Sheet2!B:B
, Sheet2!B:B <> ""
, Sheet2!A:A <> ""
, NOT(
ISERROR(
SEARCH(
REGEXREPLACE(Sheet2!A:A, " ", "")
, A2:A
)
)
)
)
, "not found"
)
)
)
Ok, I finally got it to work with the substring and SEARCH.
=Array_Constrain(TRANSPOSE(ArrayFormula(REGEXREPLACE(REGEXREPLACE(SPLIT(TEXTJOIN(", ",1,{ArrayFormula(IFERROR(HLOOKUP("Value",Sheet2!B:B,ArrayFormula(Transpose(SEQUENCE(COUNTA(Sheet2!A2:A),1,2))*(SEARCH(TRANSPOSE(SUBSTITUTE(FILTER(Sheet2!A2:A,LEN(Sheet2!A2:A))," ",)),FILTER(A2:A,LEN(A2:A)))>0)),0))),ArrayFormula(IF(SEQUENCE(COUNTA(A2:A)),";",""))}),", ;",0,0),"^, ",),"^$","not found"))),COUNTA(A2:A),1)
"Readable" version:
=Array_Constrain(
TRANSPOSE(
ArrayFormula(REGEXREPLACE(
REGEXREPLACE(
SPLIT(
TEXTJOIN(
", ",
1,
{
ArrayFormula(IFERROR(
HLOOKUP(
"Value",
Sheet2!B:B,
ArrayFormula(
Transpose(
SEQUENCE(COUNTA(Sheet2!A2:A),1,2)
)*
(SEARCH(
TRANSPOSE(
SUBSTITUTE(
FILTER(
Sheet2!A2:A,
LEN(Sheet2!A2:A)
),
" ",
)
),
FILTER(A2:A,LEN(A2:A))
)>0)
),
0
)
)),
ArrayFormula(IF(
SEQUENCE(COUNTA(A2:A)),
";",
""
))
}
),
", ;",
0,
0
),
"^, ",
),
"^$",
"not found"
))
),
COUNTA(A2:A),
1
)
I'm wondering if anyone could give me a helping hand in shuffling a comma-separated list of values in one cell in Google sheets. My data looks like this:
peter, andrew, mike, michael, ..., thomas
I'd like to randomly shuffle this string for each row and I have about a thousand rows that all have one cell that looks like this.
Any formula or link to a page where I can get closer to a solution would be greatly appreciated.
Draggable Single Formula
Here's a formula if you're ok with dragging a formula down:
=ArrayFormula(
JOIN(
", ",
Array_Constrain(
SORT(
TRANSPOSE(
{
SPLIT(A1, ", ");
RANDARRAY(1,COUNTA(SPLIT(A1, ", ")))
}),
2,
),
COUNTA(SPLIT(A1,", "))
,1
)
)
)
Two ArrayFormulas
It may be possible to combine these two into one, so I may revisit this later.
Make sure you have three columns clear. I chose C as my start column.
=ArrayFormula(
SORT(
{
ARRAY_CONSTRAIN(
SPLIT(
TRANSPOSE(
SPLIT(
TEXTJOIN(
",",
1,
(SEQUENCE(COUNTA(A:A))-1)&"|"&SPLIT(FILTER(A:A&", ",LEN(A:A)),", ")
),
","
)
),
"|"
),
COUNTA(
SPLIT(TEXTJOIN(", ",1,A:A),", ")
),
2
),
RANDARRAY(
COUNTA(
SPLIT(
TEXTJOIN(", ",1,A:A),
", "
)
),
1
)
},1,1,3,1)
)
Final result.
=ArrayFormula(
TRANSPOSE(
SPLIT(
REGEXREPLACE(
TEXTJOIN(
", ",
,
UNIQUE(
TRANSPOSE(
IF(
TRANSPOSE(FILTER(C:C,LEN(C:C)))=FILTER(C:C,LEN(C:C)),
FILTER(D:D,LEN(D:D)),
";"
)
)
)
),
", (;, )+",
";"
),
";"
)
)
)
The tricky part was getting the "group concatenation" to work.