I have data I need normalized. Any value in Col C separated by a comma needs its own row.
Here is my sheet
The Data is in Col A - Col C and the Desired Result is int Col E-ColG.
This question was helpful and I got the formula working for col C but when I try to integrate col A and B it breaks:
Transpose, Split, and Join Google Sheets
a scalable modification of #ttarchala's solution:
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(SPLIT(IFERROR(TEXTJOIN(
"♦", 1, $A3:A&"♠"&$B3:B&"♠"&IFERROR(SPLIT(C3:C, ", ")))), "♦")), "♠"),
"where Col2<>'' and Col3<>''"))
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(SPLIT(IFERROR(TEXTJOIN( "♦", 1,
SUBSTITUTE($A3:A&"♠"&$B3:B&"♠"&IFERROR(SPLIT(
REGEXREPLACE(C3:C, ", |,", "♥"), "♥")), "♠♠", ""))), "♦")), "♠"), "where Col3<>''"))
This rather long formula will do what you want
=query(
arrayformula(
split(
transpose(
split(
textjoin(
"\",
0,
$B3:B4 &
"|" &
split(C3:C4, ", ")
),
"\"
)
),
"|"
)
),
"select * where Col2 <> ''"
)
Explanation: really too long and too boring to write. Just rebuild the query starting from the innermost formulas to see how it works.
Adding the column A is left as an exercise to the reader.
Related
From what I have read, it appears that INDIRECT() does not function with ARRAYFORMULA(), however have seen some custom workaround solutions for specific situations. Could anyone assist me with modifying the following equations such that I can use ARRAYFORMULA() with them?
Equation 1:
=IF($I$11<>"", SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$M$5&"6:"&$M$5&""),'Earnings Pivot Statement'!$A$6:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A$6:A,"<="&DATE(A2,12,31)), SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$P$5&"6:"&$P$5&""),'Earnings Pivot Statement'!$A$6:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A$6:A,"<="&DATE(A2,12,31)))
Equation 2:
=IFERROR(IFNA(SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$M$5&"6:"&$M$5&""),'Earnings Pivot Statement'!$A$6:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A$6:A,"<="&DATE(A2,12,31))/O2,"-"),"-")
Equation 3:
=SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$P$5&"6:"&$P$5&""),'Earnings Pivot Statement'!$A$6:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A$6:A,"<="&DATE(A2,12,31))
Appreciate any help I can get with understanding how to modify these!
Edit: Taking Erik's suggestion of not requiring INDIRECT(), I have managed to reference the same set of data using OFFSET() with the following:
=ARRAYFORMULA(IF($I$11:I11<>"", SUMIFS(OFFSET('Earnings Pivot Statement'!$A$6, 0, $M$2-1, COUNTA('Earnings Pivot Statement'!$A$6:A)+COUNTBLANK('Earnings Pivot Statement'!$A$6:A),1),'Earnings Pivot Statement'!$A$6:A,">="&DATE(A2:A,1,1),'Earnings Pivot Statement'!$A$6:A,"<="&DATE(A2:A,12,31)), SUMIFS(OFFSET('Earnings Pivot Statement'!$A$6, 0, $P$2-1, COUNTA('Earnings Pivot Statement'!$A$6:A)+COUNTBLANK('Earnings Pivot Statement'!$A$6:A),1),'Earnings Pivot Statement'!$A$6:A,">="&DATE(A2:A,1,1),'Earnings Pivot Statement'!$A$6:A,"<="&DATE(A2:A,12,31))))
However, ARRAYFORMULA() is only populating 1 cell currently, not sure why
You are looking up data from a pivot table, which seems like an unnecessary step. Try something like this to get the total directly from 'Earnings Input':
=query(
'Earnings Input'!A1:G,
"select year(A), sum(G)
where B is not null
group by year(A)
label year(A) 'Year', sum(G) 'Total' ",
1
)
=arrayformula(
iferror(
vlookup(
G18:G,
query(
'Earnings Input'!A1:G,
"select year(A), sum(G)
where B " & if(len(I11), "= '" & I11 & "' ", "is not null") & "
group by year(A)",
1
),
2, false
)
)
)
These formulas do not require any helper columns. Cell I11 is a drop-down list that lets you select a name to filter by, or leave empty to show all.
Additional data points can be obtained like this:
=arrayformula( if( not(len(G5)) * len(F9:F), "-", iferror( F9:F / E9:E ) ) )
=arrayformula(
if(
not(len(G5)) * len(F9:F),
"-",
iferror( 100% - G9:G / isnumber(G9:G) )
)
)
=if(
len(G5),
G5 & " % (" & to_text(round(average(G9:G), 2)) & ")",
"No filter"
)
See the new Solution3 sheet.
The solution above is still a bit verbose, primarily because of the report format you have chosen. It is usually easier to display the data for all categories at once. To get an idea what that would look like, try this:
=query(
'Earnings Input'!A1:G,
"select year(A), sum(G)
where B is not null
group by year(A)
pivot B
label year(A) 'Year', sum(G) 'Total' ",
1
)
=arrayformula(
if(
isnumber(B3:J15) * isnumber(B3:B15) * isnumber(B3:J3),
B3:J15 / B3:B15,
B3:J15
)
)
See the new Solution2 sheet.
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))," ",", ")))}
I have a little problem getting the array from the function below. When the criterion of the IF function is range (At the site of B11) it stops working and returns just one not conected value. How to get the array result?
=ARRAYFORMULA(TEXTJOIN(" ", TRUE,ARRAYFORMULA(IF('Sheet1'!$B$2:$B15 = B11, 'Sheet1'!$D$2:$D15, ""))))
LINK to Sheet https://docs.google.com/spreadsheets/d/1QQGcPKI895NpwM-9oXccs8Ln4RWXAPaqVq5IBKllKFE/edit?usp=sharing
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&"",
TRIM(SPLIT(REGEXREPLACE(TRIM(FLATTEN(QUERY(QUERY({J2:J&"♥", L2:L&","},
"select max(Col2)
where Col2 <> ','
group by Col2
pivot Col1"),,9^9))), ",$", ), "♥")), 2, 0)))
Cannot figure out how to pull the results of a query with multiple rows and columns into single cells and find their details from my lookup table. Any help is greatly appreciated.
Trying this
=ArrayFormula(
QUERY({
QUERY({A4:A16,TEXTJOIN(",",TRUE,B4:C16)}, "SELECT Col1, Col2, Col3 WHERE Col1 MATCHES 'Core 1|Core 2|Core 3' LABEL Col1 'Core ID', Col2 'Full Result'")
}, "SELECT Col2 WHERE Col1 = Col1")
)
Sheet to help
It's always a headache trying to mix Query with ArrayFormula. They don't go well together.
I arrived at a nice formula, but the catch is that it relies on you sorting your data by Core Item first. You can easily achieve this with:
=SORT(A4:C16)
For this example, I placed this formula is cell N4. Then your resultant formula is:
=ArrayFormula(
{
"Core ID", "Full Result";
UNIQUE(FILTER(N4:N,N4:N<>"")),
SUBSTITUTE(
TRANSPOSE(
SPLIT(
REGEXREPLACE(
TEXTJOIN(
",",
,
UNIQUE(
TRANSPOSE(
IF(
TRANSPOSE(FILTER(N4:N,N4:N<>""))=FILTER(N4:N,N4:N<>""),
FILTER(O4:O,O4:O<>"")&
" ("&
VLOOKUP(FILTER(O3:O,O3:O<>""),A23:B53,2,)&
") - "&
FILTER(P4:P,P4:P<>"")&
" ("&
VLOOKUP(FILTER(P4:P,P4:P<>""),A23:B53,2,)&
")",
";"
)
)
)
),
",(;,)+",
";"
),";"
)
),
",",
CHAR(10)
)
})
It uses the Group Concatenate method I've adopted for stuff like this with UNIQUE, TRANSPOSE, and IF. This can probably be solved without using the precalculated SORT by substituting all instances of the N4:N, but doing it this way saves on computation time. If you need it gone, you can also hide the column or stow it in another sheet.
If you are ok breaking apart your formula then this would be an acceptable approach.
Start by Building your query criteria.
=ArrayFormula(
QUERY({QUERY({A4:A16,ArrayFormula(B4:B16&" ("&VLOOKUP(B4:B16,A23:B53,2,false)&") -
("&VLOOKUP(C4:C16,A23:B53,2,false)&")")}, "SELECT Col1, Col2 WHERE
Col1 MATCHES 'Core 1|Core 2|Core 3' LABEL Col1 'Core ID', Col2 'ALL Result'")},
"SELECT Col1, Col2 WHERE Col1 = Col1"))
Then in another column get the unique values and lastly, join the filtered values.
=UNIQUE(E4:E17)
=Join(Char(10),FILTER(F4:F12,E4:E12 = H4))
The downside to this is you will need to have multiple columns to achieve your desired result but it is easy to follow. Good luck!
In this QUERY
=QUERY(QUERY(Estimate!A2:Y,"SELECT A,D,E,F,G,H,J,Y",0)
Column Y contains a CSV list. How can I split this up into multiple rows in the results?
I tried this, without success:
=QUERY(QUERY(Estimate!A2:Y,"SELECT A,D,E,F,G,H,J,'"&SPLIT(Estimate!Y2,", ",TRUE,TRUE)&"'",0),"OFFSET 1",0)
My sheet
=ARRAYFORMULA(TRIM(SUBSTITUTE(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(
SUBSTITUTE(A2:C, " ", "♦"), "select Col1,Col2,Col3", 0)),, 999^99)), " ,"), "♦", " ")))
=ARRAYFORMULA(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(IFERROR(SPLIT(C2:C, ","))<>"", "♦"&A2:A&"♠"&B2:B&"♠"&SPLIT(C2:C, ","), ))
,,999^99)),,999^99), "♦")), "♠")))