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
utsurur
New Member

[Need Help] How to Sum Values in subtotal based on Column/Row with CountDistinct formula

Please help my problem,
I calculate measure column distinct count of device_id with a formula:

 

 

 

#_D Mobile + Wifi = CALCULATE(
    DISTINCTCOUNT(f_mw_202301_202404[device_id]),
    FILTER(f_mw_202301_202404,
        f_mw_202301_202404[category]= "Buy" || f_mw_202301_202404[category]= "Use"))

 

 

 

Value
I build visual Matrix and input #_D Mobile + Wifi in Values as image:
Snag_a2c4a4d.png

 

As shown, column subtotals and row subtotals are still distinct count (based on column and row contents). The expected result is column subtotals and row subtotals is the sum of the value of each column and row contents.
Thanks in advance. 

1 ACCEPTED SOLUTION
xifeng_L
Super User
Super User

Hi @utsurur ,

 

You can try this measure.

 

#_D Mobile + Wifi =
SUMX (
    CROSSJOIN (
        VALUES ( 'Table'[Matrix Row Field] ),
        VALUES ( 'Table'[Matrix Column Field] )
    ),
    CALCULATE (
        CALCULATE (
            DISTINCTCOUNT ( f_mw_202301_202404[device_id] ),
            FILTER (
                f_mw_202301_202404,
                f_mw_202301_202404[category] = "Buy"
                    || f_mw_202301_202404[category] = "Use"
            )
        )
    )
)

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

View solution in original post

3 REPLIES 3
xifeng_L
Super User
Super User

Hi @utsurur ,

 

You can try this measure.

 

#_D Mobile + Wifi =
SUMX (
    CROSSJOIN (
        VALUES ( 'Table'[Matrix Row Field] ),
        VALUES ( 'Table'[Matrix Column Field] )
    ),
    CALCULATE (
        CALCULATE (
            DISTINCTCOUNT ( f_mw_202301_202404[device_id] ),
            FILTER (
                f_mw_202301_202404,
                f_mw_202301_202404[category] = "Buy"
                    || f_mw_202301_202404[category] = "Use"
            )
        )
    )
)

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

Snag_a923704.png

 

Excelent @xifeng_L , thank you very much. I wish you always be healthy.  💪 😊 

Rupak_bi
Super User
Super User

If you use Measure, output will be like this only. To solve, First Create a summarize table with the same dax and then refer that table in matrix to get your desired result.



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.