# How to sum last n columns in Excel

In this article, we will learn How to sum last n columns in Excel.

Scenario:

In simple words, while working with long values in dataset. Sometimes given a condition i.e. when we need to get the sum of the last 5 or n numbers from the column. You can perform the solution to this problem easily using the excel functions as explained below.

How to solve the problem?

For this article we will be required to use the SUM function & INDEX function. Now we will make a formula out of these functions. Here we are given a range and the value of n. We need to find the SUM of the range from last n columns from the range.

Generic formula:

 = SUM ( INDEX ( ( data , 0 , COLUMNS (data) - ( n - 1 ) ) : INDEX ( data , 0 , COLUMNS (data)) )

data : range of values where sum is calculated

n : value of n to get the last n number of columns

Example:

All of these might be confusing to understand. So, let's test this formula via running it on the example shown below.

Here we have some data of numbers and we need  to find the sum of the data from the last 4 columns using the above explained formula.

Firstly,  we need to find the values corresponding to the text values, extract numerical values and then sum operation be performed over those values. Now we will use the following formula to get the sum.

Use the Formula:

 = SUM ( INDEX ( ( data , 0 , COLUMNS (data) - ( J12 - 1 ) ) : INDEX ( data , 0 , COLUMNS (data)) )

Explanation:

• COLUMNS (data) returns the number of columns in the data which is 10  And COLUMNS(data) - (4-1) returns 7 as result which shortens the formula to = SUM ( INDEX (data,0,8) : INDEX(data,0,10))
• Now INDEX function extracts all the values of the given argument column num.
• " : " this operator makes the values into array range from the column index.
• SUM function gets the array range from the required column to the last column and  performs the sum operation over those values and returns the sum as shown below.

Here the table array and value of n is given as named range and cell reference as shown in the above image.

As you can see in the above snapshot that sum of { 54 , 69 , 56 , 50 ; 92 , 54 , 51 , 30 ; 69 , 51 , 30 , 30 } comes out to be 636.

You can check the results in the snapshot given below.

Now we will perform the formula over a list of numbers instead of a table for given different values of n.

Use the Formula for the list1:

 = SUM ( INDEX ( ( list1 , 0 , COLUMNS (list1) - ( M6 - 1 ) ) : INDEX ( list1 , 0 , COLUMNS (list1)) )

The sum of the last 3 values from the range comes out to be 175. Now for the last 5 values and lst 8 values. Now copy the formula into other cells using the Ctrl + D or dragging down the cell option in excel.

As you can see in the above snapshot we obtained all the sum by extracting from the last n columns.

Here are some observational notes shown below.

Notes:

1. The formula only works with numbers.
2. The COLUMNS function returns a number as col_index.
3. The INDEX function takes 0 as an argument to get the return all values in the column.
4. Value of n cannot be greater than the number of columns in the table.
5. The list array length must be of the same as the code length else the function.

Hope this article about How to sum last n columns in Excel is explanatory. Find more articles on SUMPRODUCT functions here. Please share your query below in the comment box. If you liked our blogs, share it with your friends on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at info@exceltip.com

Related Articles

How to use the SUMPRODUCT function in Excel: Returns the SUM after multiplication of values in multiple arrays in excel.

SUM if date is between : Returns the SUM of values between given dates or period in excel.

Sum if date is greater than given date: Returns the SUM of values after the given date or period in excel.

2 Ways to Sum by Month in Excel: Returns the SUM of values within a given specific month in excel.

How to Sum Multiple Columns with Condition: Returns the SUM of values across multiple columns having condition in excel

How to use wildcards in excel : Count cells matching phrases using the wildcards in excel

Popular Articles

50 Excel Shortcut to Increase Your Productivity : Get faster at your task. These 50 shortcuts will make you work even faster on Excel.

How to use the VLOOKUP Function in Excel : This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.

How to use the COUNTIF function in Excel : Count values with conditions using this amazing function. You don't need to filter your data to count specific values. Countif function is essential to prepare your dashboard.

How to use the SUMIF Function in Excel : This is another dashboard essential function. This helps you sum up values on specific conditions.

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.