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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
andrew5083
Frequent Visitor

Prior MTD by Day DAX Calc

Hello,

My company recently switched to Power BI for our presentation layer.  I've been really struggling to master DAX time intelligence functions as our last BI solution had very intuitive, dynamic and straightforward time intelligence.

 

I've managed to re-create most of our commonly used time intelligence measures for an analysis, but am struggling with getting Prior MTD Totals by Day.  

 

This should not be an accumulated total and should not show dates past the current day in visuals/matrices.

 

These are very common measures my company uses together frequently in KPIs and reports.  The closest I've gotten to it are the measures below:

 

Daily Subtotal

 

Daily Subtotal:= 
    IF(
        SELECTEDVALUE('Date Invoice'[Full Date]
        ) 
    <= TODAY(),
       [Subtotal]
    )

 

 Prior Month Daily Subtotal

 

PM Daily Subtotal:= 
    IF(
        SELECTEDVALUE('Date Invoice'[Full Date]
        )
     <= TODAY(),
        CALCULATE([Daily Subtotal], 
            DATEADD(
            'Date Invoice'[Full Date], -1, MONTH
            )
        )
    )

 

 

The issue I'm having is the total displayed at the bottom of the PM Daily Subtotal column.  That is the total for the full month of April 2021, despite the visible numbers in the column adding up to $8,072,834.20.  I am assuming the 28-31 of May are not being used in this calc, otherwise those dates should be present in the data in the matrix?

 

The screenshot below is using test data.

andrew5083_1-1622143181676.png

 

Any advice on how to get the total for that column to line up with the data being shown?

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Screenshot 2021-05-28 230557.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL thank you for the suggestion.  Sorry for the hand holding, but how should I reference this calculated column in a measure?

amitchandak
Super User
Super User

@andrew5083 , I think you want force MTD below today

example

MTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALMTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

 

LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

or

 

Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))

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

@amitchandak thank you for your reply.

 

I tested the functions you posted.  Unfortunately these are giving me a accumulating month total.  I've created dax statements that capture this data as shown in the first two columns (MTD Accum & PMTD Accum) in the screenshot I posted.  The final total in your test column is correct.  If I can get the daily subtotal instead of an accumulating subtotal then it would work.

andrew5083_0-1622213773752.png

 

 

What I'm trying to get is a Prior MTD Daily Total, as shown in the last column of the original screenshot, but without the full month's total being referenced in the bottom total line of the screenshot.

 

I also attempted to adapt the forced date logic in your solutions to an existing test column.  This gave me the same result as the PM Daily Subtotal column I created.  The amounts posted for each day are accurate, but the total referenced at the bottom is not.

andrew5083_1-1622214447520.png

 

Could this be a bug?  We're literally forcing the date to filter to today in multiple areas in our solutions.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.