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
DanteL
Helper I
Helper I

Return sum of distinct value per category

Hi, this has been driving me mad for hours.

YearIndexMale
202011
202011
202011
202021
202021
202021
202021
202032
202032
202032
202032
202143
202143
202150
202150
202160

 

I'm trying to write a measure to return the value of Male when Index and Year is selected.

So for e.g. if i select Index 1 and 2020 (Date[Year)]) in the slicers, Male should show value of 1
Index 3, Male = 2

And when nothing is selected in Index, Male should show the total of distinct values.
Example, if 2020 is selected, and nothing selected in Index, then Male = 4 (1+1+2)

Appreciate all the help please ! Thanks !

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@DanteL 

maybe you can try group by in the power query

11.PNG12.PNG13.PNG14.PNG15.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
v-weiyan1-msft
Community Support
Community Support

Hi @DanteL ,

 

@ryan_mayu nice method! Thank you, for your quick response and the solution provided.
And based on the sample and description you provided, please try the following steps:
1.You can create Calculated table.

Dim_Year = VALUES('Table'[Year])

vweiyan1msft_0-1709779782947.png

Dim_Index = VALUES('Table'[Index])

vweiyan1msft_1-1709779811900.png

2. Use the following code to create a measure.

Measure = 
VAR SelectedYear = SELECTEDVALUE('Dim_Year'[Year])
VAR SelectedIndex = SELECTEDVALUE('Dim_Index'[Index])
VAR DistinctIndexMale = 
    SUMMARIZE(
        FILTER('Table', 'Table'[Year] = SelectedYear),
        'Table'[Index],
        "DistinctMale", MAX('Table'[Male])
    )
VAR Result = 
    SUMX(DistinctIndexMale, [DistinctMale])
RETURN
    IF(
        HASONEVALUE('Dim_Index'[Index]),
        MAXX(FILTER('Table','Table'[Year] = SelectedYear && 'Table'[Index] = SelectedIndex),'Table'[Male]),
        Result
    )

The fields of the two slicers are from the corresponding Calculated table.
When you select "2020", "1" in the slicers, Result is as below.

vweiyan1msft_2-1709779858790.png

When you select "2020" in the slicer, Result is as below.

vweiyan1msft_3-1709779876437.png

 

Best Regards,
Yulia Yan


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ryan_mayu
Super User
Super User

@DanteL 

maybe you can try group by in the power query

11.PNG12.PNG13.PNG14.PNG15.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks. Is there a way to do it with measures instead ?

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.