I have a formula that allows me to join multiple rows together and remove duplicates:
=TEXTJOIN(" ", 1, UNIQUE(TRANSPOSE(FILTER(Sheet1!A:D, NOT(REGEXMATCH(LOWER(Sheet1!A:D), "n/a"))))))
The issue I'm running in to is because this references another tab in the same sheet, it cannot be sorted by different columns without changing the results.
So what I'd like to know is: how do I modify the above formula so that it pulls the data it needs based on criteria I give it? Note this will need to be across a range of cells and includes strings of text.
After your comment I understand what you are trying to do. Basically you want to retrieve an information of the first sheet matching with your "row key".
Is there any reason why you haven't used a VLOOKUP?
For example using this formula:
=IFNA(VLOOKUP(A1,Sheet1!A:G, 7, FALSE), "VALUE NOT FOUND")
If you sort or randomize the range of column B you get a result like this:
In here you see that every description keeps up with its key.
EDIT: So after your comment it seems that you don't have your information inside a single cell. You could create this cell as a placeholder to later retrieve the information.
Or if you need you could make this inside the formula, that could make this a little messy but still could be workable.
=TEXTJOIN(" ", 1,
UNIQUE(
TRANSPOSE(
FILTER({VLOOKUP(A1, Sheet1!A:G, 3, FALSE), VLOOKUP(A1, Sheet1!A:G, 4, FALSE), VLOOKUP(A1, Sheet1!A:G, 5, FALSE), VLOOKUP(A1, Sheet1!A:G, 6, FALSE)},
NOT(LOWER({VLOOKUP(A1, Sheet1!A:G, 3, FALSE), VLOOKUP(A1, Sheet1!A:G, 4, FALSE), VLOOKUP(A1, Sheet1!A:G, 5, FALSE), VLOOKUP(A1, Sheet1!A:G, 6, FALSE)}) = "n/a")
)
)
)
)
try:
=ARRAYFORMULA(IFNA(VLOOKUP(TO_TEXT(B1:B), {QUERY(TRANSPOSE(QUERY(QUERY(
UNIQUE(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Sheet1!C:E="",,"♥"&ROW(Sheet1!C:C)&"♦"&Sheet1!C:E)),,999^99)),,999^99), "♥")), "♦"))),
"where not lower(Col2) matches 'n/a'", 0),
"select max(Col2) group by Col2 pivot Col1")), "select Col1", 0), TRANSPOSE(QUERY(QUERY(
QUERY(QUERY(UNIQUE(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Sheet1!C:E="",,"♥"&ROW(Sheet1!C:C)&"♦"&Sheet1!C:E)),,999^99)),,999^99), "♥")), "♦"))),
"where not lower(Col2) matches 'n/a'", 0),
"select max(Col2) group by Col2 pivot Col1"), "offset 1", 0),,999^99))}, 2, 0)))
Related
Columns D:H show my initial info, where two workstreams (Column D) have different issues occur (Column F:H). These issues fall under one of three categories, under Columns A:B. I want the chart to show the count of the category each issues falls under, making sure it's also showing that it's within a certain workstream.
what i was working with so far is below to match issues to the three categories
=INDEX(A:B, MATCH(F1, A:A, 0), 2)
and below to count the times a value is within the workstream group (A or B).
=countif(flatten(filter(F:H,D:D="A")),"one")
How can I combine these two?
https://docs.google.com/spreadsheets/d/1hs-Srt-qdOR44V_rmvKF-rC5DThRrQrrCfiA_jAvnH0/edit?usp=sharing
delete J:M range and use in D1:
=INDEX({QUERY(SPLIT(FLATTEN(D1:D9&"×"&VLOOKUP(F1:H9, A1:B12, 2, 0)), "×"),
"select Col1,count(Col1) where Col2 is not null
group by Col1 pivot Col2 label Col1'workstream'"); "TOTAL",
TRANSPOSE(MMULT(1*QUERY(
QUERY(SPLIT(FLATTEN(D1:D9&"×"&VLOOKUP(F1:H9, A1:B12, 2, 0)), "×"),
"select count(Col2) where Col2 is not null
group by Col2 pivot Col1"), "offset 1", ),
SEQUENCE(COUNTUNIQUE(D1:D9), 1, 1, 0)))})
formula explanation
Say I had a list like this.
Group 1 Group 2
Edward, C Kate, A
Mark, F Ava, Z
Now, in a different column =IF(COUNTIF('Gender'!$A$2:$B$3, "Kate, A"), "", "") is my current formula. I would like to make the first set of empty speech marks return Group 1 or Group 2 depending what column it is. I still require the COUNTIF because my actual sheet has values which will not be contained in either column.
Thanks.
try:
=INDEX(IFNA(VLOOKUP("Kate, A", SPLIT(FLATTEN(
IF(Gender!A2:B="",,Gender!A2:B&"×"&Gender!A1:B1)), "×"), 2, 0)))
update:
=INDEX(IFNA(VLOOKUP(A1:A, QUERY(SPLIT(FLATTEN(
IF(Groups!B2:C="",,Groups!B2:C&"×"&Groups!A1&"×"&Groups!B1:C1),
IF(Groups!F2:G="",,Groups!F2:G&"×"&Groups!E1&"×"&Groups!F1:G1)), "×"),
"select Col1,max(Col3) where Col2 is not null
group by Col1 pivot Col2 label Col1'"&A1&"'"), {2, 3}, 0)))
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))
Looking for a more efficient way, possibly array formula for Min/Max down a column. Not sure if array formulas work with this function as I can't get it to.
=ArrayFormula(MAX(INDIRECT("Data!E"&(K42:K169)&":E"&(K43:K170-1))))
=ARRAYFORMULA(MAX(VLOOKUP(K42:K169, {ROW(Data!A:A), Data!E:E}, 2, 0)&VLOOKUP(K43:K170-1, {ROW(Data!A:A), Data!E:E}, 2, 0)))
Note that I am using ROW(Data!A:A) instead of simply ROW(A:A) because the range in current sheet doesn't fit that of sheet Data!.
Here is my current code copied down columns in my sheet.
=MAX(INDIRECT("Data!E"&(K42-1)&":E"&(K43-1)))
Just need a more efficient way. Am I correct that using INDIRECT results in slow calculation times.
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(
INDIRECT("Data!E"&K42&":E"&MAX(K42:K))&","&IF(MOD(ROW(
INDIRECT("Data!A1:A"&COUNTA(L42:L)*K41)), K41)=0, "♦", ),,999^99), "♦")), ","),
"where Col2 is not null", 0)),
"select "&TEXTJOIN(",", 1, IF(LEN(L42:L),
"max(Col"&ROW(A42:A)-ROW(A42)+1&")", ))&"")),
"select Col2"))
I am trying to search Data!A2:A for multiple matches to Search!A2:A. When a match is found, get the value(s) from Data!B2:B and place them in CSV format in Search!B2:B.
This QUERY works, but I would like to somehow only enter it one time at the top of the column rather than fill it down manually. When I attempted to wrap it in ARRAYFORMULA, I simply replicated the first result down the column.
=JOIN(", ",QUERY(Data!$A$2:$B,"SELECT B WHERE A = '"&A2&"'",0))
Here is my sample spreadsheet
=ARRAYFORMULA(REGEXREPLACE(TRIM(IFERROR(VLOOKUP(A2:A, {QUERY(QUERY(Data!A2:B,
"select A,count(A) where A is not null group by A pivot B", 0), "select Col1 offset 1", 0),
TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(QUERY(QUERY(Data!A2:B,
"select count(A) where A is not null group by A pivot B", 0), "offset 1", 0)),
QUERY(QUERY(Data!A2:B,
"select count(A) where A is not null group by A pivot B", 0), "limit 0", -1)&",", ))
,,999^99))}, 2, 0))), ",$", ))