Home » excel » Excel: sum of a column, but apply a function to each cell before sum

Excel: sum of a column, but apply a function to each cell before sum

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a basic excel spreadsheet like this:

A           B           C          D       etc..
10%         219.10      34.2       6.4     etc..
6%          45.10       36.2       7.4     etc..
4%          419.10      54.2       9.4     etc..
Totals:     [SUM]       [SUM]      [SUM]   ( -- update - need totals here -- )

I would like to sum all the values in column B, C and D. Each cell value needs to be multiplied by the % in column A before doing the sum()

I could manually create a new column to contain the % calculation, and sum that column up, but I’m hoping to do it without the additional column.

I found this which I think is on the right track but am a little lost at implementing it.

(planning to write this calculation to an excel spreadsheet created from a php script based on values in a simple mysql database)

How to&Answers:

EDIT

For the updated question, all you need is (in B5)

=SUMPRODUCT(B2:B4 * $A2:$A4)

Copy to the right


For E2, use

=SUMPRODUCT(B2:D2 * $A2)

This means B2*A2 + C2*A2 + D2*A2.

But, did you know that mathematically speaking, it is the same as

  B2*A2 + C2*A2 + D2*A2
= A2 * (B2+C2+D2)

Which is just this below?

=A2*SUM(B2:D2)

Looking at your etc, if you need to expand it rightwards, just keep column A locked in SUMPRODUCT, or use the SUM. Example below for up to J

=SUMPRODUCT(B2:J2 * $A2)
=A2*SUM(B2:J2)

And copy down.

Answer:

Use array formulas e.g. http://office.microsoft.com/en-us/excel-help/introducing-array-formulas-in-excel-HA001087290.aspx

These are generally expressed by the control-shift-enter idiom