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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.