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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

SUM values of a column with DISTINCT

Hey, everyone!
My table follows this structure:

Cod  Name     Weight
XXXexample10
XXXexample10
YYYexample20
ZZZexample35
ZZZexample35
AAAexample4
CCCexample8


As you can see, it contains a column that has repeated values ​​(Cod column). I wante to create a calculated column that SUMS all the values ​​in the Weight column, but doing this sum by DISTINCT Cod. So the final SUM whould be 10 + 20 + 35 + 4 + 8 = 77.
Can someone help me?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hello

You can download my PBI file from here.

I hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hello

You can download my PBI file from here.

I hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

measure= sumx(summarize(Table,Table[Cod],Table[Name],Table[Weight]),[Weight])

or

measure= sumx(summarize(Table,Table[Cod],Table[Name],"_1", max(Table[Weight])),[_1])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Download example PBIX file here

Not sure it makes sense to create a column for a result that is a single value?

In Power Query use this code to get the result

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiIUNJRSq1IzC3ISQWyDA2UYnVwCkdGRqIIG0GEo6KiUISNTfEJOzo6ogibgEWdnZ1RRC2UYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cod  " = _t, #"Name     " = _t, Weight = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Weight", Int64.Type}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type", {"Cod  "}),
    Total = List.Sum(#"Removed Duplicates"[Weight])
in
    Total

 

Starting with this

start.png

 

Result

end.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi, @PhilipTreacy 

Thanks for the response!
I gave the initial idea of ​​being a column, but it works better if it was a measure.

The final result I would like is a measure that shows the sum of all values ​​in the Weight column, but only counting the distincts Cods. So, based on the example table above, the final result of the measure would be 77.
I already did the SUM part, but I don't know how to do the SUM by DISTINCT Cods. 
Right now, my measure is like this: 

 

measure = SUMX(Table1,Table1[Weight])

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.