Question

I'd like to use array function to get conditional sum based on two columns. Given the example, for each ID I want to calculate the sum of value column if column B is -1.

  ID  | B |  value |
________________________
1 A1   1      2
2 A2   1      3
3 A3   1      4
4 A3  -1      5
5 A3  -1      1
6 A2   1      5
7 A1   1      1
8 A2  -1      2

The outcome should be:

      ID  |  value_total |
________________________
1 A1   1      0
2 A2   1      2
3 A3   1      6
Was it helpful?

Solution

This gives the outcome you show from your example data:

SO17971702 example

Edit Seems to have ‘done the trick’, so some explanation:

=SUMIFS syntax is

SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

So in this case the formula is summing ColumnD values where in the corresponding row the ColumnB value is whatever happens to be in ColumnB for the row containing the formula and the ColumnC value is -1.

The answer does not repeat a column for unique values of ID because only three distinct IDs are shown in the example and, conveniently, these are the first three and in order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top