Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum of row n through last row

I want to create a TOTAL row at the top of my spreadsheet. In this row, each cell should be the SUM of the values in the column below the TOTAL row.

So for example, if the total row is Row 1, cell A1 should be the SUM of A2 through the last row in column A. The number of rows in the spreadsheet will grow over time, so I can't just say SUM(A2:A500) because eventually there will be row 501, 502, etc.

like image 683
Nick Petrie Avatar asked Aug 31 '12 22:08

Nick Petrie


People also ask

How do you sum last row in Excel?

In Excel, we are able to sum the last n columns of any data set by using the SUM, INDEX and COLUMNS functions. The SUM function adds all given values, the INDEX function returns a value or reference to a cell, while COLUMNS returns the number of columns in an array.

How do you sum across a row?

If you need to sum a column or row of numbers, let Excel do the math for you. Select a cell next to the numbers you want to sum, click AutoSum on the Home tab, press Enter, and you're done. When you click AutoSum, Excel automatically enters a formula (that uses the SUM function) to sum the numbers.


2 Answers

If you want something that just works in Google Spreadsheets (as the title suggests), you can use open-ended ranges:

=SUM(A2:A) 

In Excel, you can specify the maximum rows for that version; for example, for 2007 and 2010:

=SUM(A2:A1048576) 

This will work in Google Spreadsheets as well, and is beyond the current theoretical row limit in GSheets (400000)*.

Edit: *The quoted limit of the new version of Sheets is actually now 2 million cells.

like image 129
AdamL Avatar answered Sep 21 '22 07:09

AdamL


Try this

=SUM(OFFSET(A1,1,0,ROWS(A:A)-1,1)) 

Works in both Excel and Google Docs

One downside: by using OFFSET the formula becomes Volatile ie is calculated every time the sheet calculates irrespective of data change.

like image 24
chris neilsen Avatar answered Sep 24 '22 07:09

chris neilsen