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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jaartz
New Member

Changing Subtotal Aggregations for Measures in a Matrix Visual

Hi everyone,

 

I have a dataset that looks like this:

 

jaartz_0-1659417960807.png

 

This is currently represented in a matrix visual. The subtotal of the first row returns the first value in the row and the subtotal of the last row returns the sum. I'm attempting to return the last value in the last row as the subtotal for that aggregated period. The DAX measure for the first row is CALCULATE(SUM(Fact_Table[Amount]), PREVIOUSMONTH(Dim_Date[Date])) and, I guess because it uses PREVIOUSMONTH, DAX evaluates that to January as the aggregation, which is my desired result. The DAX measure for the last row is simply SUM(Fact_Table[Amount]). I understand that this defaults the aggregation of the subtotal to a sum, but I'm a bit stumped about how to change that aggregation for the subtotal shown to what I'd really like it to be: the last value available in that subtotal period (i.e. $645 should be the subtotal for the last row, not the sum of all values). I've reviewed this post, but that, as expected, returns the max of the month/year in the date table as a whole and the corresponding value. Really all I'm attempting to do is use the last available month in the last column as the aggregation for that subtotal. Any help with this would be greatly appreciated. Thank you!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@jaartz , One option is to use

last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Why previousmonth does not give result when datesmtd is giving it: https://youtu.be/1KkoJehRVeg

 

 

Another is swich using isinscope

 

if(isinscope (Date[Month Year]) , CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH))) , CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month)) )

 

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

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

View solution in original post

2 REPLIES 2
jaartz
New Member

Thank you!

amitchandak
Super User
Super User

@jaartz , One option is to use

last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Why previousmonth does not give result when datesmtd is giving it: https://youtu.be/1KkoJehRVeg

 

 

Another is swich using isinscope

 

if(isinscope (Date[Month Year]) , CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH))) , CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month)) )

 

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

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
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.

Top Solution Authors