(Excel examples for Beginners)
In this end-to-end excel example, you will learn – Excel formula for Beginners – How to Sum last n columns in Excel.
Excel formula for Beginners – How to Sum last n columns in Excel
Generic formula
=SUM(INDEX(data,0,COLUMNS(data)-(n-1)):INDEX(data,0,COLUMNS(data)))
Explanation
To sum the last n columns in a table of data (i.e. last 3 columns, last 4 columns, etc.) you can use a formula based on the INDEX function. In the example shown, the formula in K5:
=SUM(INDEX(data,0,COLUMNS(data)-(K4-1)): INDEX(data,0,COLUMNS(data)))
where “data” is the named range C5:H8
How this formula works
The key to understanding this formula is to realize that the INDEX function can be used to return a reference to entire rows and entire columns.
To generate a reference to the “last n columns” in a table, we build a reference in two parts, joined by the range operator. To get a reference to the left column, we use:
INDEX(data,0,COLUMNS(data)-(K4-1))
Since data contains 6 columns, and K4 contains 3, this simplifies to:
INDEX(data,0,4) // all of column 4
To get a reference to the right column in the range, we use:
INDEX(data,0,COLUMNS(data))
Which returns a reference to column 6 of the named range “data”, since the COLUMN function returns 6:
INDEX(data,0,6) // all of column 6
Together, the two INDEX functions return a reference to columns 4 through 6 in the data (i.e. F5:H8), which resolve to an array of values inside the SUM function:
SUM({15,14,10;9,12,12;7,9,9;12,13,13})
The SUM function then calculates and returns the sum, 135.
Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.
Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners
Latest end-to-end Learn by Coding Projects (Jupyter Notebooks) in Python and R:
All Notebooks in One Bundle: Data Science Recipes and Examples in Python & R.
End-to-End Python Machine Learning Recipes & Examples.
End-to-End R Machine Learning Recipes & Examples.
Applied Statistics with R for Beginners and Business Professionals
Data Science and Machine Learning Projects in Python: Tabular Data Analytics
Data Science and Machine Learning Projects in R: Tabular Data Analytics
Python Machine Learning & Data Science Recipes: Learn by Coding
R Machine Learning & Data Science Recipes: Learn by Coding
Comparing Different Machine Learning Algorithms in Python for Classification (FREE)
There are 2000+ End-to-End Python & R Notebooks are available to build Professional Portfolio as a Data Scientist and/or Machine Learning Specialist. All Notebooks are only $29.95. We would like to request you to have a look at the website for FREE the end-to-end notebooks, and then decide whether you would like to purchase or not.
Excel formula for Beginners – How to Calculate running total in Excel