cancel
Showing results for
Did you mean:
Highlighted
Frequent Visitor

## Sum of Column A if Column B is unqiue

If I have a table like

Col1 Col2

a       1

a       1

a       1

b       3

b       3

b       3

c       5

c       5

How would I calculate the sum of Col2 based on unique Col1 (i.e in this example sum = 9)

I have tried

SUMX(Filter('table', DISTINCT('table'[Col1])),'table'[Col2]))

and calculate(sum('table'[Col2], filter('table', distinct('table'[Col1]))))

1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Visitor

## Re: Sum of Column A if Column B is unqiue

You may try to create the measure using the SUMMARIZE (by the column1), then use MAX function as expression (this works only if there is only one value for each value in the column1)
Measure = SUMX(SUMMARIZE(Table1, Table1[Column1], "Column2", MAX(Table1[Column2])), [Column2])
3 REPLIES 3
Frequent Visitor

## Re: Sum of Column A if Column B is unqiue

You may try to create the measure using the SUMMARIZE (by the column1), then use MAX function as expression (this works only if there is only one value for each value in the column1)
Measure = SUMX(SUMMARIZE(Table1, Table1[Column1], "Column2", MAX(Table1[Column2])), [Column2])
Super User III

## Re: Sum of Column A if Column B is unqiue

In your data, if Col1 is a, will Col2 always be 1?

If not, you'll need to figure out some way to decide which Col2 is the correct value to use in the sum.  Otherwise, you can use this:

`SumByCategory = SUMX(DISTINCT(Table[Col1]),FIRSTNONBLANK(Table[Col2],[Col2]))`
Frequent Visitor

## Re: Sum of Column A if Column B is unqiue

Thanks, that works!

Announcements

#### ‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

#### Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

#### April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

#### MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors