Excel formula for Beginners – How to Sum every nth column in Excel

 

(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)

Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

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

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!

 

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