I have 2 sheets: "Planning" and "Utilization" (example)
Planning: Employees assigned to projects for each week. Some projects are not fixed but need to be simulated (checkbox = true).
Utilization: Shows the utilization of each employee for each week. Only rows with:
a) no checkbox in Planning!A2:A
b) rows with checkbox checked
c) rows with project name in Planning!B2:B are to be considered.
I'd like to have a formula in Utilization!B2 that would calculate the sums for Utilization!B2:E4. With infinite rows and columns in Planning sheet.
try:
=QUERY(QUERY({Planning!A:H};
"select Col3,sum(Col5),sum(Col6),sum(Col7),sum(Col8)
where not Col1 = FALSE
and Col3 is not null
group by Col3"; 0);
"offset 1"; 0)
UPDATE:
=ARRAYFORMULA(QUERY(QUERY({Planning!A:Z};
"select Col3,"&
TEXTJOIN(","; 1; IF(Planning!E1:1="";;"sum(Col"&COLUMN(E:Z)&")"))&"
where not Col1 = FALSE
and Col3 is not null
group by Col3"; 0);
"offset 1"; 0))
FIX for 'get' error:
=ARRAYFORMULA(QUERY(QUERY({Planning!A:D\Planning!E:Z*1};
"select Col3,"&
TEXTJOIN(","; 1; IF(Planning!E1:1="";;"sum(Col"&COLUMN(E:Z)&")"))&"
where not Col1 = FALSE
and Col3 is not null
group by Col3"; 0);
"offset 1"; 0))
For infinite rows and Columns, I like to use OFFSET() so you might try this formula in A1 on a new tab.
=ARRAYFORMULA({QUERY(QUERY({Planning!A:D\N(OFFSET(Planning!E1;;;ROWS(Planning!E:E);COUNTA(Planning!E1:1)))};"select Col3, "&TEXTJOIN(",";TRUE;"SUM(Col"&SEQUENCE(COUNTA(Planning!E1:1);1;5)&")")&" where Col2 is not null group by Col3";0);"offset 1";0)})
Related
In this spreadsheet
Cols G and H give the total of each Account Type, from the data (A1:D)
If sum Dr - sum Cr > 0, then only this is shown in col G.
=if(sumifs(C:C,A:A,F2)-sumifs(D:D,A:A,F2)>0, sumifs(C:C,A:A,F2)-sumifs(D:D,A:A,F2),"")
If sum Cr - sum Dr > 0, then only this is shown in col H
=if(sumifs(D:D,A:A,F2)-sumifs(C:C,A:A,F2)>0, sumifs(D:D,A:A,F2)-sumifs(C:C,A:A,F2),"")
I am looking for an array formula which replaces these summifs formula, so that if either new Account Types (e.g. Type E, Type F etc) are added or new rows of data are added, then the formula would automatically calculate the sum Dr or sum Cr, instead of having to copy the formula down
try this in cell G2:
=BYROW(F2:F,LAMBDA(fx,IF(fx="",,LAMBDA(cx,dx,{IF(cx-dx>0,cx-dx,),IF(dx-cx>0,dx-cx,)})(SUMIF(A:A,fx,C:C),SUMIF(A:A,fx,D:D)))))
-
Use query(), like this:
=arrayformula(
lambda(
aggregated,
lambda(
account, balance,
{
"Account Type", "Dr", "Cr";
account,
if( balance >= 0, balance, iferror(1/0) ),
if( balance < 0, -balance, iferror(1/0) )
}
)(
query(aggregated, "select Col1", 0),
query(aggregated, "select Col2", 0)
)
)(
query(
A3:D,
"select A, sum(C) - sum(D)
where A is not null
group by A
label sum(C) - sum(D) '' ",
0
)
)
)
You can set a QUERY that finds both entire columns like this:
=QUERY(A2:D,"SELECT A,SUM(C)-SUM(D),SUM(D)-SUM(C) where A is not null group by A",1)
And check with LAMBDA if there are negative values and change them to null:
=LAMBDA(a,INDEX(IF(a<0,,a)))(QUERY(A2:D,"SELECT A,SUM(C)-SUM(D),SUM(D)-SUM(C) WHERE A is not null group by A",1))
If the values in your result table are just for display, you can use the QUERY format clause to hide negative values, such that the whole thing can be generated within a single QUERY:
=QUERY(A2:D,"select A,sum(C)-sum(D),sum(D)-sum(C) where A is not null group by A label sum(C)-sum(D) 'Dr',sum(D)-sum(C) 'Cr' format sum(C)-sum(D) '0;',sum(D)-sum(C) '0;'",1)
I want to filter with the week number in Col3 but the below function is producing an empty array.
=QUERY(Form Responses!A:T,"Select Col9,Col8,Col2,Col3,Col4,Col7,Col19,Col20, Col5, Col6, Col18 Where Col1 = 'On-time' AND Col3 ='"&WEEKNUM(TODAY())&"'",1)
use:
=QUERY(Form Responses!A:T,
"select Col9,Col8,Col2,Col3,Col4,Col7,Col19,Col20,Col5,Col6,Col18
where Col1 = 'On-time'
and Col3 ="&WEEKNUM(TODAY()), 1)
i have data and want to sum it with weeknum in every name condition, but i can't do that it always error parse or empty value.
this my query
=query(A1:D8,"select sum(D) where D='"&G2&"' and B='"&H1&"' label sum(D)'' ")
=query(A1:D8,"select sum(D) where D='"&G2&"' and weeknum(A)=weeknum('"&H1&"') label sum(D)'' ")
this my link
https://docs.google.com/spreadsheets/d/1AHnu-IrFQuh7scbtoQriB_7frhvLUYfO9gIX2yqiXBY/edit?usp=sharing
use:
=QUERY(A:D, "select C,sum(D) where B = "&H1&" group by C label sum(D)''", 0)
if you want 0 values use:
=ARRAYFORMULA({UNIQUE(FILTER(C2:C, C2:C<>"")),
IFNA(VLOOKUP(UNIQUE(FILTER(C2:C, C2:C<>"")),
QUERY(A:D, "select C,sum(D) where B = "&H1&" group by C label sum(D)''", 0), 2, 0), 0)})
I would like to import a sheet by 2 different filter function. The first one need to include every row where the value of column 14 is equal to 1, the second one need to exclude rows where column H contains one of those strings "alc" "alcool" "vin". I've seen it in previous questions here google-sheet-query-matches-function-doesnt-exclude-strings. However when i try to add the first filter into my previous formula it doesn't work, here is my formula :
=FILTER(
QUERY(
IMPORTRANGE("URL"; "Sheet!A:BE");
"SELECT Col1, Col3, Col4, Col26, Col8, Col30, Col40, Col41, Col44, Col45, Col49 WHERE Col14 = "1""
);
NOT(REGEXMATCH(IMPORTRANGE("URL"; "Sheet!H:H"); "(?i)alc|vin|alcool"))
)
I try both using and not using "" as the values of my column are numbers but none of them work
use:
=FILTER(QUERY(IMPORTRANGE("1RV1-mxrd4wjVBw8hNu1yQAOZvlaO0jD5Ar5AArg-7QE";
"wc-product-export-27-11-2020-1606486738987!A:BE");
"select Col1,Col3,Col4,Col26,Col8,Col30,Col40,Col41,Col44,Col45,Col49
where Col14 = 1");
NOT(REGEXMATCH(QUERY(IMPORTRANGE("1RV1-mxrd4wjVBw8hNu1yQAOZvlaO0jD5Ar5AArg-7QE";
"wc-product-export-27-11-2020-1606486738987!A:BE");
"select Col8
where Col14 = 1"); "(?i)alcool|vin|alc")))
or shorter:
=INDEX(QUERY(IMPORTRANGE("1RV1-mxrd4wjVBw8hNu1yQAOZvlaO0jD5Ar5AArg-7QE";
"wc-product-export-27-11-2020-1606486738987!A:BE");
"select Col1,Col3,Col4,Col26,Col8,Col30,Col40,Col41,Col44,Col45,Col49
where Col14 = 1
and not lower(Col8) contains "&JOIN(" and not lower(Col8) contains "; "'"&SPLIT(
"alcool|vin|alc"; "|")&"'")))
=iferror(QUERY(importorders!A:H,“Select count(A) where C = ‘Thailand Tour’ and month(H) = “&MONTH(A3)-1&“and year(H) = “&year(A3)&” label count(A) ‘’“,1),0)
It’s basically just counting to see how many orders I had in each month.
https://docs.google.com/spreadsheets/d/1Of6cdFYaOzCFwPdZ4ABItD6dghMjHhafRWmDJWaznbg/edit#gid=711075203
use this in B3 cell:
=ARRAYFORMULA(IFNA(VLOOKUP(A3:A, QUERY({importorders!A2:C,
EOMONTH(importorders!H2:H, -1)+1},
"select Col4,count(Col1)
where Col3 = 'Thailand Tour'
and Col4 is not null
group by Col4
label count(Col1)''", 0), 2, 0), 0))
Try
=query(A2:H,"select Year(H), Month(H)+1, C, Count(H) where C is not null and C like 'Thailand%' group by Year(H), Month(H)+1,C label C'Tour',Year(H)'Year',Month(H)+1'Month'")
This data applied to a pivot table might provide a more digestible analysis.
Report Extract