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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Newbie12345
Regular Visitor

Need Urgent HELP! on DAX

Dear All,

I want to show the sub total in a separate column in the matrix visual as shown in the screenshot. 
Population is a measure, not a direct column from the database. 
NOTE: Country is from different table and State is from different table. 
           Same State Name will be there in different countries

Can someone please help me around with this?


Newbie12345_1-1712312708143.png

 

 


Thank you.


1 ACCEPTED SOLUTION
v-nuoc-msft
Community Support
Community Support

Hi @Newbie12345 

 

@gmsamborn Thank you very much for your prompt reply, and here allow me to make some comments of my own.

 

Power BI does not inherently support displaying subtotals in separate columns within the same matrix. However, you can create a separate visual to show totals.

 

For your question, here is the method I provided:

 

Check to see if there is a relationship between the "Country" and "State" tables in the model. If not, make sure there is a public key that links these tables directly or indirectly.

 

vnuocmsft_0-1712556267187.png

 

Since you mentioned that "Population" is a metric and not a direct column, you will need to create a metric using DAX to correctly calculate subtotals for different states and countries.

 

Sub Total = 
SUMX(
    FILTER(
        'Country / State', 
        'Country / State'[Country] = MAX('Country / State'[Country])
    ), 
    'Country / State'[Measure Population]
)

 

You can create a card for displaying Sub Total.

 

vnuocmsft_1-1712556472448.png

 

Also used in conjunction with the slicer for showing population totals under different countries.

 

vnuocmsft_2-1712556518637.png

Regards,

Nono Chen

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

 

 

View solution in original post

4 REPLIES 4
v-nuoc-msft
Community Support
Community Support

Hi @Newbie12345 

 

@gmsamborn Thank you very much for your prompt reply, and here allow me to make some comments of my own.

 

Power BI does not inherently support displaying subtotals in separate columns within the same matrix. However, you can create a separate visual to show totals.

 

For your question, here is the method I provided:

 

Check to see if there is a relationship between the "Country" and "State" tables in the model. If not, make sure there is a public key that links these tables directly or indirectly.

 

vnuocmsft_0-1712556267187.png

 

Since you mentioned that "Population" is a metric and not a direct column, you will need to create a metric using DAX to correctly calculate subtotals for different states and countries.

 

Sub Total = 
SUMX(
    FILTER(
        'Country / State', 
        'Country / State'[Country] = MAX('Country / State'[Country])
    ), 
    'Country / State'[Measure Population]
)

 

You can create a card for displaying Sub Total.

 

vnuocmsft_1-1712556472448.png

 

Also used in conjunction with the slicer for showing population totals under different countries.

 

vnuocmsft_2-1712556518637.png

Regards,

Nono Chen

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

 

 

lukiz84
Memorable Member
Memorable Member

SubTotal = CALCULATE([Population], ALL(YourStateTable))

Dear @lukiz84 ,

Thanks for your response! 
The problem here is, I have same state name in other countries too, so we can not use ALL, 
I tries ALLEXCEP as well but since it is a matrix, it is giving row level value along with subtotal. 
Want I am trying to get here is, only Subtotal like a merged single value (as shown in the screenshot above)

Hi @Newbie12345 

 

I'm not sure you can make a matrix column appear to be a Excel merged column.

 

Regarding your measure, would this help?

Subtotal = 
    IF(
        NOT HASONEVALUE( 'Table'[State] ),
        CALCULATE(
            SUM( 'Table'[Population] ),
            REMOVEFILTERS( 'Table'[State] )
        )
    )

 

I hope this helps.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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