Google Sheets – How to Sum Last 12 Columns

google sheets

I'm trying to track my recent 12 months spend on an ongoing basis. Each month a new column is added for the new month, but I want Column B to show the sum of the most recent 12 months.

I've set up a sheet that can be edited at https://docs.google.com/spreadsheets/d/1GNAyLuRHDXJYpCndVIIovIB4_Y-QXgH2nOMn1OSNTVc/edit?usp=sharing

The formula that I've tried in cell B2 is (not working):

=SUM(QUERY(SORT(C2:AZ2, Column(C2:AZ2)*ISNUMBER(C2:AZ2), 0), "select * limit 12"))

Best Answer

Keeping in mind that we can't see your data or layout, when I merely "eye" this, it seems you should be using TRANSPOSE on the elements of your sort. Try this:

=SUM(QUERY(SORT(TRANSPOSE(C2:AZ2), TRANSPOSE(Column(C2:AZ2)*ISNUMBER(C2:AZ2)), 0), "select * limit 12"))

If that does not work, please consider sharing a link to your sheet (or a copy of your sheet, or a spreadsheet containing sample data representative of your sheet), being sure to set the link's Share permission to "Anyone with the link > Editor."