Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

Query Totals for rows and columns in Google Sheets

I need help to combine the following commands to use a single Google Query command to obtain the Totals for Rows and Columns without relying on Pivot Tables:

QUERY 1 =QUERY(TESTDATA!A1:C16, "SELECT A, SUM(C) GROUP BY A PIVOT B",1)

QUERY 2 =QUERY(TESTDATA!A1:C16, "Select SUM (C) GROUP BY A label SUM (C) 'NAME ROW TOTALS'")

QUERY 3 ={transpose(Query(TESTDATA!A1:C16, "Select SUM (C) GROUP BY B label SUM (C) 'MONTH COLUMN TOTALS'"))}

https://docs.google.com/spreadsheets/d/15i1E8AZHORRmPlu1VQqFRN1_7-aUyAz-hlYMOUtIlY4/edit?usp=sharing

I would like to return the following result:

enter image description here

Thank you very much JA

question from:https://stackoverflow.com/questions/65916147/query-totals-for-rows-and-columns-in-google-sheets

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use:

={{QUERY(TESTDATA!A1:C, "select A,sum(C) group by A pivot B", 1),
   QUERY(TESTDATA!A1:C, "select sum(C) group by A label sum(C) 'NAME TOTAL'")}; TRANSPOSE(
   QUERY(TESTDATA!A1:C, "select sum(C) group by B label sum(C) 'MONTH COLUMN TOTALS'"))}

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...