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.
Please help.
>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
Subtotalrows just in case

