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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
g_hill
Frequent Visitor

How to sum a field based on a distinct count of another field

Hello, I'm trying to build a measure that sums the number of children on active cases based on a table where cases can appear multiple times.
Below is a sample of the data. I want to know the total children on active cases, but I don't want to count the same case twice. The result for the sample table is 4 (Case Codes 1001 and 1003 appear twice so I don' want to count them twice).
 
Case CodeChildrenStatus
10001Active
10012Active
10012Active
10023Closed
10031Active
10031Active
10044Closed
 
Here's what I've got so far but it's totalling 7 as it's counting cases more than once.
 
Children on Active Cases = SUMX(
    CALCULATETABLE('Table1',
    'Table1'[Status] = "Active Tenancy",
       SUMMARIZE('Table1','Table1'[Case Code])
    ),
    'Table1'[Children])
 
How can I ammend the measure to only look at a case once?
 
Thanks
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Try the following measure:

Children Active, Distinct =
VAR _table = SUMMARIZE(FILTER('Cases', 'Cases'[Status] = "Active"), 'Cases'[Case Code], "Child Amount", SELECTEDVALUE('Cases'[Children]))
RETURN
SUMX(_table, MAX([Child Amount]))
 
This is assuming that your main table is called cases, you can replace that with whatever your table is called, this worked in the sample dataset I built in power BI from the little table in your post:
TobyNye_0-1700052983866.png

The duplicate values are in there, they just don't show in visuals as they are identical:

TobyNye_1-1700053024411.png

Hope that helps, let me know if you have any issues or questions.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Try the following measure:

Children Active, Distinct =
VAR _table = SUMMARIZE(FILTER('Cases', 'Cases'[Status] = "Active"), 'Cases'[Case Code], "Child Amount", SELECTEDVALUE('Cases'[Children]))
RETURN
SUMX(_table, MAX([Child Amount]))
 
This is assuming that your main table is called cases, you can replace that with whatever your table is called, this worked in the sample dataset I built in power BI from the little table in your post:
TobyNye_0-1700052983866.png

The duplicate values are in there, they just don't show in visuals as they are identical:

TobyNye_1-1700053024411.png

Hope that helps, let me know if you have any issues or questions.

That's working on my main data table. Thanks for your help!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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