Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use Query() to generate subtotal group by a column under the Query() result?

I am wondering if there are smart and elegant ways to create subtotal below a query result in using Google Sheets’ query() function.

Referring to the image below, if I have DATA with Currency values, can I generate a table with subtotal based on currency using Query() or some forms of combined Query()?

The challenge is that the number of rows and number of currencies are dynamic in DATA. To use query to generate Report A is not hard as shown but I just cannot think of a smart way using formulas (instead of App Scripts or pivot table) to create Report B when number of currencies is dynamic.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please help.

enter image description here

>Solution :

Here’s one approach you may test out:

=reduce(A3:C3,unique(tocol(B4:B,1)),lambda(a,c,vstack(a,filter(A:C,B:B=c),hstack("Subtotal",c,sumif(B:B,c,C:C)))))
  • you can use conditional formatting to highlight the Subtotal rows just in case

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading