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.
Related
Since Query is such a powerful formula, i try to avoid my team members to avoid messing up the pivot. I try to to come out with query to replace my pivot. Based on the raw data Google Sheet Trix, i try to sum column based on the criteria i have described in Grey colour (B2:E2). Appreciate if someone could lay some foundation for me, so i can further tweaks based on the formula you create here.
I created a new tab and entered the following in cell A1:
=query(
{'RAW DATA'!B:B,'RAW DATA'!E:E,'RAW DATA'!G:J},
"select Col1, sum(Col3), sum(Col4), sum(Col5), sum(Col6)
where Col1 is not null and Col2<>'Black and Yellow'
group by Col1"
)
Use a query() with a group by clause, like this:
=query(
'RAW DATA'!B1:J,
"select B, sum(G), sum(H), sum(I), sum(J)
where B is not null and E <> 'Black' and E <> 'Yellow'
group by B",
1
)
The result table will only include weeks where there is at least one data row where E is not Black or Yellow.
See the new Solution sheet in your sample spreadsheet.
Here is your solution. which also included in new tab named Solution Pivot in Query.
=ArrayFormula(QUERY(SPLIT(FLATTEN(TO_TEXT('RAW DATA'!B2:B)&"|"&'RAW DATA'!E2:E&"|"&'RAW DATA'!G1:J1&"|"&'RAW DATA'!G2:J),"|"),"Select Col1, Sum(Col4) where Col2 is not null And Col2 <> 'Yellow' And Col2 <> 'Black' Group by Col1 Pivot Col3 label Col1 'Date'"))
I am looking to build a formula that will check columns for a true value and if true return the first column name, in order...
Below is the formula I have been trying to build but it is not working as expected although I think I am close.
=ARRAYFORMULA(IF(HLOOKUP($A16,{Sheet1!$B$2:$E$5,Sheet2!$B$8:$E$11},{3,4,5},0)=TRUE,{Sheet2!$A$3:$A$5,Sheet1!$A$3:$A5,""))
Let me illustrate. Sheet 1 and Sheet 2 contain names with who has what (checkbox items). With a formula in cell B16 that will populate both to the right and down with all the names that contain a TRUE value in the looked up value (A:A).
Above image was manually typed in, the formula does not work at all.
Please help!
EDIT: Link to sheet
try:
=INDEX(IFERROR(VLOOKUP(A14:A, SUBSTITUTE(REGEXREPLACE(SPLIT(FLATTEN(
QUERY(SUBSTITUTE(QUERY(SPLIT(FLATTEN(
IF({B3:E5; B9:E11}=TRUE,
{B2:E2&"♦"&A3:A5&"♣"&ROW(A3:A5);
B8:E8&"♦"&A9:A11&"♣"&ROW(A9:A11)}, )), "♦"),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"),
" ", "♥"),,9^9)), " "), "(♣\d+)", ), "♥", " "),
SEQUENCE(1, COUNTUNIQUE(B2:E2, B8:E8))+1, 0)))
demo sheet
Here is another approach (similar to player0's, but different enough to warrant the separate answer:
=ArrayFormula(IFERROR(TRIM(SPLIT(VLOOKUP(FILTER(A3:A,A3:A<>""),REGEXREPLACE(SPLIT(FLATTEN(QUERY(QUERY(SPLIT(QUERY(FLATTEN({IF(Sheet1!B2:E<>TRUE,,Sheet1!B1:E1&"~|"&Sheet1!A2:A&",");IF(Sheet2!B2:E<>TRUE,,Sheet2!B1:E1&"~|"&Sheet2!A2:A&",")}),"Select * WHERE Col1 Is Not Null"),"|"), "Select MAX(Col2) where Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1"),, 9^9)),"~"),"[,\s]+$",""),2,FALSE),","))))
I've added it into your spreadsheet in a new sheet ("Erik Help").
If you have more than two sheets' to include, just find this section of the formula and continue the pattern:
{ IF(Sheet1!B2:E<>TRUE,,Sheet1!B1:E1&"~|"&Sheet1!A2:A&","); IF(Sheet2!B2:E<>TRUE,,Sheet2!B1:E1&"~|"&Sheet2!A2:A&",") }
I am currently using char (10) to merge columns, from a separate tab called "scripts", into one cell based on a name.
=IFERROR(TEXTJOIN(CHAR(10),1,QUERY(Scripts!$A$3:A,"select B, C, D, E where A ='"&A1&"'")))
my information shows up in a list. is there a way to combine columns B+C and then D+E.
row 1 is what my data looks like on "scripts" tab.
row 7 is what the data looks like with the above equation.
row 12 is what i would like the equation to do.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A1:A, QUERY(
{Scripts!A:A, Scripts!B:B&" "&Scripts!C:C&CHAR(10)&Scripts!D:D&" "&Scripts!E:E},
"where Col1 is not null"), 2, 0)))
update:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(QUERY(
{Data!A2:A&"×", CHAR(10)&TEXT(Data!B2:B, "m/d/yy")&
CHAR(10)&Data!C2:C&", "&Data!D2:D&", "&Data!E2:E, ROW(Data!A2:A)},
"select max(Col2) where not Col1 starts with '×' group by Col3 pivot Col1")
,,9^9)), "×")), "^"&CHAR(10), ))
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!
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))