Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
hanr
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
Anonymous
Not applicable

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

View solution in original post

3 REPLIES 3
Cmcmahan
Resident Rockstar
Resident Rockstar

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]))
Anonymous
Not applicable

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

Thanks, that works!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.