jkupczak
jkupczak

Reputation: 3031

Sum range in Google Sheets of only unique values

I need a formula to sum a column of values. But I only want to sum the rows that have an ID that are unique among the entire range. See the example below where I have 6 rows, but there are only 3 unique IDs. My ideal outcome is a sum of 6 by adding one instance of UNIQUEID-00A, UNIQUEID-00B, and UNIQUEID-00C.

Notes:

See the linked Google Sheet below for a copy of this.

ID Value
UNIQUEID-00A 1
UNIQUEID-00B 2
UNIQUEID-00C 3
UNIQUEID-00A 1
UNIQUEID-00B 2
UNIQUEID-00C 3

https://docs.google.com/spreadsheets/d/1bU4J1RL5S0a_NvFjW_KVpiKi8603Tj9iVPeNzBlw-OA/edit?usp=sharing

Upvotes: 2

Views: 5164

Answers (2)

player0
player0

Reputation: 1

use:

=SUM(SORTN(B3:B, 9^9, 2, A3:A, 1))

enter image description here

  • sum B column
  • while returning all rows 9^9
  • that are unique 2
  • within A column
  • in whatever order 1

Upvotes: 1

The God of Biscuits
The God of Biscuits

Reputation: 3177

Given the above table in A1:B7:

=sum(index(unique(A2:B7),,2))

UNIQUE returns the distinct rows of the range, INDEX (with column parameter = 2) to return only the value column, then SUM the result.

EDIT Based on the updated requirements, with the IDs in, for example, column A and the values to be summed in column C, use something like:

=sum(index(unique({A2:A,C2:C}),,2))

I'm assuming that there is no data below your input table. The UNIQUE here will return an extra blank row because of the unlimited range, but SUM will disregard it.

Upvotes: 3

Related Questions