March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi everyone,
I have a dataset that looks like this:
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!
Solved! Go to Solution.
@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/
Thank you!
@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/
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
91 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
73 | |
68 |