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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
anuj_gupta487
Frequent Visitor

DAX measure to work based on ISINSCOPE of matrix visual

Hi Everyone,

I am trying to write a DAX for a matrix visual, that will be used in Values section in visualization pane, and matrix has a heirarchy for ManagedGroup and UserName (will go in Rows in visualization pane).
I need to show the DistinctCount of AccountId at user level but at group level, is should be sum of user level values.

So based on below sample data, it should show

Admin - 4 (2 + 2)

Lead - 4 (1+ 2 + 1)

Here is the sample data:

ManagedGroupUserNameAccountIdDateActionTaken
Admin Aaronefgh2/28/2023
Admin Aaronefgh4/23/2023
Admin Aaronghij5/15/2023
Admin Johncdef6/16/2023
Admin Johnefgh3/15/2023
LeadBrockabcd5/16/2023
LeadBrockabcd3/24/2023
LeadCathyabcd6/27/2023
LeadCathyghij5/11/2023
LeadDerekijkl4/9/2023

 

Matrix visual:

anuj_gupta487_0-1697017423063.png

For Group Level, it is recalculating the DISTINCTCOUNT of AccountId, so the group level values are
Admin - 3
Lead - 3

Also in ROW Grand Total -> again need to show sum of values at group level, so that would be 8 (currently showing as 5)

ItemsNew Measure definition: 

ItemsNew =
VAR _isgroup = NOT(ISINSCOPE(Sheet3[UserName]))
VAR _items =
    IF(_isgroup,
        COALESCE(DISTINCTCOUNT(Sheet3[AccountId]),0),
        COALESCE(DISTINCTCOUNT(Sheet3[AccountId]),0)
    )
return _items

------------------------------------------------------------------------------

I was trying to use SUMMARIZE and do the sumx for group level, but it will return the table not scalar value and not able to reference the table column created in SUMMARIZE for any other DAX function
SUMX(
SUMMARIZE(Sheet3[UserName], Sheet3[UserName], "NewColumn", DISTINCTCOUNT(Sheet3[AccountId])),
"NewColumn"
)

I added DateActionTaken because user will have external page level filter and based on the date filter, the values needs to change, so cannot summarize the data in underlying table

Could you please help me with that
  

1 ACCEPTED SOLUTION
anuj_gupta487
Frequent Visitor

I was able to resolve it.
Using this DAX in the measure now:
ItemsNew =  
VAR _isgroup = NOT(ISINSCOPE(Sheet3[UserName]))  
RETURN  
IF(  
    _isgroup,  
    SUMX(  
        VALUES(Sheet3[UserName]),  
        CALCULATE(DISTINCTCOUNT(Sheet3[AccountId]))  
    ),  
    DISTINCTCOUNT(Sheet3[AccountId])  
)  

here the VALUES function is going to give a table with all the distinct user in that group, and then SUMX using CALCULATE will iterate over all the users and calculate the distinctcount of AccountId

Note: I was wrong about the SUMX function, it applies the calculation row by row and then sums up all the values, in the end it will return a scalar value only.

View solution in original post

1 REPLY 1
anuj_gupta487
Frequent Visitor

I was able to resolve it.
Using this DAX in the measure now:
ItemsNew =  
VAR _isgroup = NOT(ISINSCOPE(Sheet3[UserName]))  
RETURN  
IF(  
    _isgroup,  
    SUMX(  
        VALUES(Sheet3[UserName]),  
        CALCULATE(DISTINCTCOUNT(Sheet3[AccountId]))  
    ),  
    DISTINCTCOUNT(Sheet3[AccountId])  
)  

here the VALUES function is going to give a table with all the distinct user in that group, and then SUMX using CALCULATE will iterate over all the users and calculate the distinctcount of AccountId

Note: I was wrong about the SUMX function, it applies the calculation row by row and then sums up all the values, in the end it will return a scalar value only.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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