Related
I have the following formula:
=ARRAYFORMULA(QUERY(IFERROR(FLATTEN(SPLIT(FLATTEN(REPT(REGEXEXTRACT(SPLIT(A1:A4, " "),
"(?:\d+x)?(.+)")&"×", IFERROR(REGEXEXTRACT(SPLIT(A1:A4, " "), "(\d+)x"), 1)*1)), "×"))),
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''"))
This counts the number of entries in column A, extracting the variable text like 2x and 1x, then lists them as unique cells accompanied by a count of each (while ignoring empty cells).
Now, I'd like to modify this to count associated checkboxes in 3 previous columns, comparing with the unique entries of the original column, as well as comparing the variable number of 2x and 1x so that it appropriately assigns the values.
In other words, I want it to turn out like so:
I've tried to modify the previous formula by adding (what I thought was) an additional range to the second FLATTEN.
=ARRAYFORMULA(QUERY(IFERROR(FLATTEN(SPLIT(FLATTEN(REPT(REGEXEXTRACT(SPLIT(D1:D14, " "),
"(?:\d+x)?(.+)")&"×", IFERROR(REGEXEXTRACT(SPLIT(D1:D14, " "), "(\d+)x"), 1)*1)), "×"),
SPLIT(REPT(COUNTIF(A1:A=true,D4:D<>"")*1), "×"))),
"select Col1,count(Col1) where Col1 is not null group by Col1 order by count(Col1) DESC label count(Col1)''"))
Among many others as I've begun to understand the formula given, I also tried a very roundabout way, first removing the QUERY part of the above to separate the Unique Strings into one column, and count into the other:
=FLATTEN(REPT(COUNTIF(B1:C=true,D1:D=F1),IFERROR(REGEXEXTRACT(SPLIT(N4:N56, " "), "(\d+)x"), 1)*1))
None of those worked.
So again, how would I get the following results?
try:
=ARRAYFORMULA(QUERY(""&IFERROR(FLATTEN(SPLIT(FLATTEN(
IF((A1:C15=TRUE)*NOT(REGEXMATCH(D1:D15, "\d+x")), D1:D15,
IF(REGEXMATCH(D1:D15, "\d+x"), REPT(REGEXEXTRACT(SPLIT(D1:D15, " "), "\d+x(.*)")&"×",
REGEXEXTRACT(SPLIT(D1:D15, " "), "(\d+)x")*1), ))), "×"))),
"select Col1,count(Col1) where Col1 is not null group by Col1
order by count(Col1) DESC label count(Col1)''"))
I have a list of sessions, I want to be able to import the ones that have been rescheduled (along with the new rescheduled session) to another sheet. So under colC one will say 'Rescheduled' and the other will say 'Attended'. So what I'd like to do is grab the participant name, but only if it shows up more than once, so I'd get both the rescheduled session and the new session. I tried using importrange and query, but couldn't quite get it right. How can I do this?
https://docs.google.com/spreadsheets/d/10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc/edit?usp=sharing
try:
=INDEX(REGEXEXTRACT(FLATTEN(QUERY(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY({
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C"),
FLATTEN(QUERY(TRANSPOSE(
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C")),,9^9))},
"select max(Col4) where Col1 is not null group by Col2 pivot Col3")),
"where Col1 matches 'Rescheduled|Attended'", )),
"where Col1 is not null and Col2 is not null"),
"offset 1", )),
"(\d+/\d+/\d+) (.*) (Att.*|Res.*)"))
Formula Explanation:
Take the IMPORTRANGE
Merge all columns into one column
Create a virtual array {}
Pass into QUERY and pivot the data
Transpose the result
Use query to get only needed columns
Transpose back
Compare 1st and 2nd columns and remove
Remove header row
Flatten data into one column and split into the 3 needed columns
and if that's not enough:
=INDEX(REGEXREPLACE(SORT(TEXT(REGEXEXTRACT(FLATTEN(
QUERY(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY({
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C"),
FLATTEN(QUERY(TRANSPOSE(
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C")),,9^9))},
"select max(Col4) where Col1 is not null group by Col2 pivot Col3")),
"where Col1 matches 'Rescheduled|Attended'", )),
"where Col1 is not null and Col2 is not null"),
"offset 1", )),
"(\d+/\d+/\d+) (.*) (Att.*|Res.*)"), {
"yyyymmdd\×m/d/yyyy", "#", "#"}), 2, 0, 1, 1), "^(\d+×)", ))
demo sheet
Thank you beforehand for your kind response.
Problem: I am trying to do a sheet to sort out the 3 top categories of a given range as shown by the attached screen grab.
enter image description here
I only managed to get the results by using the "large" command. "=large(range,n)". Using this I got the value but what I need is the column index/id rather than the numeric values.
Any ideas on how I would go about achieving this?
Thanks for your reply.
Try the following maybe:
Formula in G2:
=TRANSPOSE(QUERY(TRANSPOSE({A$1:E$1;A2:E2}),"Select Col1 Order by Col2 desc limit 3"))
It's definitely possible in arrayformula.
Using vlookup, a sequence of numbers for the search key:
=arrayformula(sequence(max(if(A:E<>"",row(A:A),))-1,columns(A:E)))
...and a range of columns that are sorted by each row of numbers:
=arrayformula({
sequence((max(if(A:E<>"",row(A:A),))-1)*columns(A1:E1)),
sort({
array_constrain(int((row(A2:A)-2)/(columns(A:E)))+1,(max(if(A:E<>"",row(A:A),))-1)*columns(A1:E1),1),
array_constrain(iferror(split(flatten(if(A2:E<>"",A1:E1&char(9999),)&A2:E),char(9999)),),(max(if(A:E<>"",row(A:A),))-1)*columns(A1:E1),2)
},1,1,3,0)
})
The final formula for the solution, in cell G2:
=arrayformula(
array_constrain(
vlookup(
sequence(max(if(A:E<>"",row(A:A),))-1,columns(A:E)),
{sequence((max(if(A:E<>"",row(A:A),))-1)*columns(A1:E1)),sort({array_constrain(int((row(A2:A)-2)/(columns(A:E)))+1,(max(if(A:E<>"",row(A:A),))-1)*columns(A1:E1),1),array_constrain(iferror(split(flatten(if(A2:E<>"",A1:E1&char(9999),)&A2:E),char(9999)),),(max(if(A:E<>"",row(A:A),))-1)*columns(A1:E1),2)},1,1,3,0)}
,3,0),
max(if(A:E<>"",row(A:A),))-1,3)
)
It will work with blank cells in some of the rows.
The width of the source data is determined by:
=columns(A1:E1)
and the height of the source 'numbers' by:
=max(if(A:E<>"",row(A:A),))-1 (it needs to sit within an arrayformula).
you may use this superior formula:
=ARRAYFORMULA(ARRAY_CONSTRAIN(IFERROR(SPLIT(FLATTEN(SPLIT(QUERY(FILTER(
QUERY(SPLIT(FLATTEN(IF(A2:E="",,ROW(A2:A)&"×"&A2:E&"×"&A1:E1)), "×"),
"select Col3 where Col2 is not null order by Col1,Col2 desc"), COUNTIFS(
QUERY(SPLIT(FLATTEN(IF(A2:E="",,ROW(A2:A)&"×"&A2:E&"×"&A1:E1)), "×"),
"select Col1 where Col2 is not null order by Col1,Col2 desc"),
QUERY(SPLIT(FLATTEN(IF(A2:E="",,ROW(A2:A)&"×"&A2:E&"×"&A1:E1)), "×"),
"select Col1 where Col2 is not null order by Col1,Col2 desc"),
SEQUENCE(COUNTA(A2:E), 1, ROW(A2)), "<="&SEQUENCE(COUNTA(A2:E), 1, ROW(A2)))<4)&
FLATTEN(IFERROR(SEQUENCE(MAX((A2:E<>"")*ROW(A2:A)), 3)*
{"a", "a", 0})),,9^9), 0)), " ")), 9^9, 3))
Need to get that output : Empty cells should be removed and need to get all that in 2 columns without empty cells.
try in GS:
=ARRAYFORMULA(IF(A:B=""; C:D; A:B))
={QUERY(FLATTEN(A1:G), "where Col1 is not null skipping 2"),
QUERY(QUERY(FLATTEN(A1:G), "where Col1 is not null offset 1"), "skipping 2")}
Here is my formula (I have edited the name of my sheet as I cannot allow access to it).
=QUERY(IMPORTRANGE("my sheet","Prices"),"select Col1 where Col4 contains '"& L1 &"' limit 1",1)
This is working perfectly for all entries except 1 of them where it is importing 2 cells (the first one blank, the second with the desired result). Since the cell below is filled it cannot overwrite it, and I don't want it to. What would cause this phantom empty cell and how do I prevent it from happening?
if the blank undesired cell is in the first column add and Col1 is not null like:
=QUERY(IMPORTRANGE("my sheet", "Prices"),
"select Col1
where Col4 contains '"&L1&"'
and Col1 is not null
limit 1", 1)
if you have actual line break issue use regex with \n like:
=ARRAYFORMULA(REGEXREPLACE(QUERY(IMPORTRANGE("my sheet", "Prices"),
"select Col1
where Col4 contains '"&L1&"'
limit 1", 1), "\n", ))