Google Sheets Text Join to join character from columns into row - google-sheets

have data like this
and want result like this
using this formula:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(TRANSPOSE(QUERY(QUERY(
IF(D2:D<>"", {C2:C&"♠", D2:D&","}, ),
"select max(Col2) where Col1 is not null group by Col2 pivot Col1")
,,999^99)), "♠")), ",$", ))
make the result like this
Can someone figure it out, How to fix this formula?
Thanks

Related

Finding the top 3 values and returning the column ID

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

Combining rows based on IDs on 2 columns Formula in Google Sheets

I have data that looks like this:
And I want it to look like this:
Formula ideas?
Thanks!
Maria
try:
=ARRAYFORMULA(TRIM(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY({A2:A&"×"&B2:B,
TRIM(FLATTEN(QUERY(TRANSPOSE({"×"&C2:D}),,9^9))),
TRIM(FLATTEN(QUERY(TRANSPOSE(C2:D),,9^9)))},
"select Col1, max(Col2) where Col3 is not null group by Col1 pivot Col3"),
"offset 1", 0)),, 9^9)), "×")))

Formula to fill a two dimensional grid with computed value from a table

Here is a problem to solve with a Google Sheets formula.
I have a big table (sheet “data” with headers on the first row) with those columns:
A, product reference
B: customer
C to F, KPI1 to KPI4
On another sheet, a grid of product references (A2:A) by customer (B1:1).
Now I need to fill each cell from the grid with the concatenation of KPIs (data!C24&"|"&data!D24&"|"&data!E24&"|"&data!F24)
Could you workout a single formula to fill all the cells?
Here is a sample spreadsheet with the data and grid sheet:
https://docs.google.com/spreadsheets/d/1iA_kw4kKw99Qk69X4tST9U-QN2SeG2EN3KEeyG6AtHs/edit?usp=sharing
I have worked out a formula which does the job, though with very poor performance on large dataset:
=ARRAYFORMULA(
IFNA(
VLOOKUP(
$B3:$B&"|"&C$2:$2,
ARRAYFORMULA(
{data!A2:A&"|"&data!B2:B,data!C2:C&"|"&data!D2:D&"|"&data!E2:E&"|"&data!F2:F}
),2,0
),""
)
)
Solution
Use an ArrayFormula on a Query with Pivot:
=ARRAYFORMULA(
QUERY(
{data!A2:A, data!B2:B, data!C2:C&"|"&data!D2:D&"|"&data!E2:E&"|"&data!F2:F},
"select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2",0
)
)
a shorter version of previous answer (no need for pre-sorting coz pivot will sort it on its own):
=ARRAYFORMULA(QUERY(
{data!A2:A, data!B2:B, data!C2:C&"|"&data!D2:D&"|"&data!E2:E&"|"&data!F2:F},
"select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2", 0))
Try this on the first cell of your grid:
=ArrayFormula(query(sort({data!A:A,data!B:B,transpose(substitute(query(transpose(data!C:F),,4)," ","|"))},1,true,2,true),"select Col1, max(Col3) where Col1 is not null group by Col1 pivot Col2",0))

Phrase Frequency formula for Google Sheets

I have a column of search terms and would like to find out all the two-word phrases in this column and the frequency of each of all them. Does anyone know of a formula in Google Sheets that can help me accomplish this?
=ARRAYFORMULA(IFERROR(QUERY(IF(SPLIT(A1:A, " ")>0, A1:A, ),
"select Col2,count(Col2)
where Col2 is not null
and Col3=''
group by Col2
label count(Col2)'frequency'"),
QUERY(IF(SPLIT(A1:A, " ")>0, A1:A, ),
"select Col2,count(Col2)
where Col2 is not null
group by Col2
label count(Col2)'frequency'")))
pste in C2 and drag down:
=COUNTA(FILTER(A:A, SEARCH("*"&B2&"*", A:A)))

Arrange query output by sheet name

thanks in advance.
Is there a way to arrange my multiple sheets query output by sheets name? so there is a separation between the two when they stack on top of each other?
=QUERY({orange!A2:I24;'apple'!A2:I26},"select Col1,Col2 where Col1 !='' ",1)
cheers to all.
={query({orange!A2:I24},"select Col1,Col2, 'orange' where Col1 !='' ",1);
query({'apple'!A2:I26},"select Col1,Col2, 'apple' where Col1 !='' ",1)}
The only way is to hardcode sheet names. There's no formula to get sheet names automatically.
Unless you have some specific data marker to differentiate between sheets, I don't think it's possible. But you may well use two queries like,
=ARRAYFORMULA({QUERY({orange!A2:I24},"select Col1,Col2 where Col1 !='' ",1);QUERY({'apple'!A2:I26},"select Col1,Col2 where Col1 !='' ",1)})
If you have a specific data marker,
=QUERY({orange!A2:I24;'apple'!A2:I26},"select Col1,Col2 where Col1 !='' order by Col3",1)
Where Col3, i.e., C column should be say,1 in orange sheet and 2 in Apple sheet.

Resources