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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

SUM of distinct values in a group

Hello,

 

I am fairly new to DAX so i am sure it would have been a common case but i am not able to find a solution.

 Sample data  for the problem :

Ishan25_0-1604560177205.png

 

I have three columns and i want the sum to based on distinct values in item and cost group.

For example in the above dataset i need cost 1,000 only once since it is for the same item but 2,000 to be counted twice as it is for different items while calculating sum.

 

I have used the following formula: CALCULATE(SUM(ITEM), GROUPBY( TABLE_NAME, ITEM, COST))

But this gives me sum of cost as 7,000

 

 

Any help would be appreciated.

Thanks in Advance!!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

You can try your measure this way, hope you have a similar number for each item.



Total = 
SUMX(
    SUMMARIZE( table5, Table5[ITEM], "A", MAX(Table5[COST])),
    [A]
)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

6 REPLIES 6
kymramosrpo
Advocate IV
Advocate IV

Thank you for sharing the measure you tried to use! This helped me with mine, as my data model looks like this:

Account IDProduct IDTransaction DateCountedRowsFromAnotherTable
(linked by Product ID)
ABCProd11/1/2020100
ABCProd21/5/202050
DEFProd32/2/202020

 

What I wanted to get is a total of 150 for account, "ABC" for the year 2020, and it worked!

Raj_sharma123
Frequent Visitor

This measure works, thanks for the awesome solution.

amitchandak
Super User
Super User

@Anonymous , Try a measure like

sumx(Values(Table[item]) , calculate(max(Table[Cost])))

This is exactly what i needed today, I cant believe it was so simple. Thank you!

Anonymous
Not applicable

I was also facing same problem, and it worked for me, 
Thankyou so much.

Fowmy
Super User
Super User

@Anonymous 

You can try your measure this way, hope you have a similar number for each item.



Total = 
SUMX(
    SUMMARIZE( table5, Table5[ITEM], "A", MAX(Table5[COST])),
    [A]
)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Kudoed Authors