Home > front end >  getting sum of item quantities grouped by item groups
getting sum of item quantities grouped by item groups

Time:11-03

I have the following data:

LOC ITEM GROUP MONTH PCS
X A1 A 01/01/2022 8
Y A1 A 01/01/2022 76
Z A1 A 01/01/2022 11
X A2 A 01/01/2022 9
Y A2 A 01/01/2022 19
Z A2 A 01/01/2022 13

I need to get the sum of PCS for each LOC/ MONTH summed by GROUP

My tentative query so far is:

QUERY(DATA;"SELECT LOC,ITEM,GROUP,SUM(PCS) WHERE LOC='X' AND GROUP='A' AND MONTH='01/01/2022' GROUP BY LOC,GROUP,MONTH,PCS";1)

My expected results is:

LOC GROUP MONTH PCS
X A 01/01/2022 17

the test spreadsheet with data, formula results is here

Thank you in advance

CodePudding user response:

use:

=QUERY(DATA;
 "SELECT A,C,D,SUM(E) 
  WHERE A='"&SEL_L&"' 
    AND C='"&SEL_G&"' 
    AND D = date '"&TEXT(SEL_M; "e-m-d")&"' GROUP BY A,C,D"; 1)
  • Related