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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Problem for Creating DAX measure for Row Total in Matrix Visual

Dear Forum Members, 

I have a data table of individuals' records of receiving service in welfare agencies. The data table has service start and end dates from which I can calcuate the length of stay (and its categories) in service. The table also has client demographics, such as age, gender, and race. 

I want to  know the number of records (exits) who exit services in each category of length of stay, and I would also like to break down the numbers by gender and race and age. 

In the screenshot below, the first matrix visual is for gender. The two values in are the number of exits (a Dax Measure) for each gender, and the total exits (also a DAX Measure for all gender row total). In the following DAX measure for row total [M_Exits_nol_gender], [M_Exits_Sum] is the measure for number of exits (just simple sum of records). I use ALL(Excel_eachstate[gender]) as a filter to get the row total for each Length of Stay category acoss the genders. For example, the row total for row header 'one week' is 76340. It seems I can also use ALLSELECTED in place of ALL to get the row total. 

M_Exits_nol_gender = CALCULATE(
    [M_Exits_Sum],
    ALL(Excel_eachstate[gender]) 
    )

LijunChen_0-1717043471268.png

However, when I created and used a similar DAX Measure for row total in the Matrix for Race (and age), the matrix visuales do not show the row total (eg. 76340 for "one week") but the same as the number for each gender category. See 2nd table abvoe.  Following is the DAX measure for the row total across race (racecat4). 

M_Exits_nol_race = CALCULATE(
    [M_Exits_Sum],
    All(Excel_eachstate[racecat4]) 
    )

 Does anyone know what is the reason for this? Is there anyway I can get the DAX measure to work correct? 

 

Besides creating the DAX measrue for row total separately for gender and race (and age), I would also like to create one single Matrix visual and use a fields parameter of Gender, race and age as a slicer and as a column of the matrix. This can show the values  of numbe of exits and row totals dynamically depending on the selected fields in the slicer.  See 3rd table and slicer in screenshot. But in this case, I wonder how I can create a DAX measure dynamically for the selected slicer field. I tried to write the DAX measure:  

M_Exits_all_demographic = CALCULATE(
    [M_Exits_Sum],
    All(Excel_eachstate[racecat4], Excel_eachstate[gender])
    )
But this does not work (either ALL or ALLSELECTED) because it still only shows the correct row total for Gender, not for race or age. 
 
I would appreciate any of your advice and suggestions. 
 
Thanks. 

 

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , to me seems like you want to switch measures using selectedvalue of field parameter. I am using two parameters, but you can use var and create dynamic measure

 

Switch TOPN with Field Parameters: https://amitchandak.medium.com/switch-topn-with-field-parameters-299a0ae3725f

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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