(Excel examples for Beginners)
In this end-to-end excel example, you will learn – Excel formula for Beginners – How to Sum every nth column in Excel.
Excel formula for Beginners – How to Sum every nth column in Excel
Generic formula
=SUMPRODUCT(--(MOD(COLUMN(rng)-COLUMN(rng.first)+1,n)=0),rng)
Explanation
To sum every nth column, you can use a formula based on the SUMPRODUCT, MOD, and COLUMN functions.
In the example shown, the formula in L5 is:
=SUMPRODUCT(--(MOD(COLUMN(B5:J5)-COLUMN(B5)+1,K5)=0),B5:J5)
How this formula works
At the core, uses SUMPRODUCT to sum values in a row that have been “filtered” using logic based on MOD. The key is this:
MOD(COLUMN(B5:J5)-COLUMN(B5)+1,K5)=0
This snippet of the formula uses the COLUMN function to get a set of “relative” column numbers for the range which looks like this:
{1,2,3,4,5,6,7,8,9}
This goes into MOD like so:
MOD({1,2,3,4,5,6,7,8,9},K5)=0
where K5 is the value for N in each row. The MOD function returns the remainder for each column number divided by N. So, for example, when N = 3, MOD will return something like this:
{1,2,0,1,2,0,1,2,0}
Note that the zeros appear for column 3, 6, 9, etc. The formula uses =0 to force a TRUE when the remainder is zero and a FALSE when not, then we use a double-negative (–) to coerce TRUE and FALSE to ones and zeros. That leaves an array like this:
{0,0,1,0,0,1,0,0,1}
Where 1s now indicate “nth values”. This goes into SUMPRODUCT as array1, along with B5:J5 as array2. SUMPRODUCT then does its thing, first multiplying, then summing products of the arrays.
The only values that “survive” multiplication are those where array1 contains 1. In this way, you can think of the logic of array1 “filtering” the values in array2.
Sum every other column
If you want to sum every other column, just adapt this formula as needed, keeping in mind that the formula automatically assigns 1 to the first column in the range. To sum EVEN columns, use:
=SUMPRODUCT(--(MOD(COLUMN(A1:Z1)-COLUMN(A1)+1,2)=0),A1:Z1)
To sum ODD columns, use:
=SUMPRODUCT(--(MOD(COLUMN(A1:Z1)-COLUMN(A1)+1,2)=1),A1:Z1)
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.
Sign up to get end-to-end “Learn By Coding” examples from us.
Excel formula for Beginners – How to find Max of every nth column in Excel
R tutorials for Business Analyst – R Aggregate Function: Summarise using Group_by()
Excel formula for Beginners – How to Sum if one criteria multiple columns in Excel