Forum Discussion

Mirithu's avatar
Mirithu
Helper II
5 years ago
Solved

Month-To-Date Fails

Hi

I have a report in which I was calculating Month-To-Date and Year-To-Date values using TOTALMTD and TOTALYTD functions respectively, successfully. But after crossing over into this year 2021, the Month-To-Date is no longer working (gives (Blank)) but the Year-To-Date still working correctly.

 

I have recreated the issue using a simple Data table with three columns:-

RecordID with 64 unique rows;

RecordDate with dates from 1st January to 8th January 2021 (today is 9th January where I am);

RecordAmount with currency values that total 8,112,554.00

 

I also have a Date table with a Start Date of 01/01/2021 and End Date of 31/12/2021.

 

I have a one-to-many relationship between the Date in Date table and RecordDate in Data table.

 

DAX:

The count and sum are calculated using the formulas:

 

TotalCount = COUNT ( Data[RecordID] )

TotalValue = SUM ( Data[RecordAmount] )

 

 The Year-To-Date formulas are as follows, giving the result as 64 for count and 8,112,554.00 for value:

 

YTDCount = TOTALYTD( [TotalCount], 'Date'[Date] )

YTDValue = TOTALYTD( [TotalValue], 'Date'[Date] )

 

However the following Month-To-Date formulas are giving (Blank) result:

 

MTDCount = TOTALMTD( [TotalCount], 'Date'[Date] )

MTDValue = TOTALMTD( [TotalValue], 'Date'[Date] )

MTDValue2 = 
    CALCULATE( 
        [TotalValue], DATESMTD('Date'[Date])
    )

 

Ideally, since we are in the first month of the year, the Month-To-Date formulas should give the same result as the Year-To-Date.

 

But why are these Month-To-Date formulas not working? Where am I going wrong? Why were they working till 31st December 2020?

 

Here's the Data table data:

 

RecordIDRecordDateRecordAmount
RID242953901/01/20212,550.00
RID626639101/01/20218,542.00
RID276621001/01/20214,785.00
RID712125401/01/202174,186.00
RID594811601/01/2021362,514.00
RID746970801/01/202126,987.00
RID409968201/01/2021478,963.00
RID950902301/01/202196,857.00
RID261388402/01/2021579,246.00
RID238316402/01/20216,985.00
RID875766802/01/202154,879.00
RID280738002/01/202116,487.00
RID637015502/01/20215,241.00
RID556551802/01/2021621,687.00
RID888768702/01/2021147,896.00
RID970544002/01/2021321,654.00
RID835254903/01/202121,258.00
RID510132003/01/20213,254.00
RID461959903/01/20213,659.00
RID532407003/01/202123,568.00
RID104884403/01/20215,263.00
RID235588303/01/2021489,423.00
RID342187603/01/2021123,698.00
RID420551603/01/2021123,456.00
RID279571004/01/20217,125.00
RID460842604/01/202132,584.00
RID533178104/01/2021365,987.00
RID965697904/01/202135,358.00
RID755454304/01/20212,546.00
RID444266704/01/202195,623.00
RID918187004/01/20217,598.00
RID637980904/01/20212,587.00
RID617390605/01/202121,578.00
RID819434905/01/2021336,987.00
RID903376905/01/20212,579.00
RID919042705/01/202169,874.00
RID342203405/01/20215,213.00
RID513820405/01/202195,847.00
RID215928305/01/20219,587.00
RID918113505/01/20212,589.00
RID935973506/01/202163,636.00
RID709090906/01/20219,482.00
RID760767206/01/20218,417.00
RID710217406/01/2021784,512.00
RID542743506/01/20213,578.00
RID858692606/01/202125,697.00
RID993633206/01/20214,718.00
RID589243006/01/20214,736.00
RID734752707/01/20215,798.00
RID240718307/01/202191,917.00
RID920312107/01/20218,954.00
RID501254607/01/2021895,623.00
RID953809807/01/20211,598.00
RID397804107/01/20214,781.00
RID830412007/01/2021362,514.00
RID717260607/01/20216,914.00
RID371752508/01/20211,247.00
RID763597308/01/2021125,469.00
RID630324208/01/202196,578.00
RID218631808/01/2021695,847.00
RID736530508/01/202124,987.00
RID757746808/01/202147,547.00
RID811135208/01/202185,749.00
RID804428308/01/202155,555.00
  • Mirithu probably your date table is till end of the month and it is calculating MTD for dec 2021, you need to restrict it until TODAY(), update your measure like this

     

    MTD = 
    TOTALMTD ( 
    SUM ( 'MTD'[RecordAmount] ),  
    CALCULATETABLE ( VALUES ( 'Calendar'[Date] ),  'Calendar'[Date] <= TODAY() ) 
    )

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

3 Replies

  • Mirithu probably your date table is till end of the month and it is calculating MTD for dec 2021, you need to restrict it until TODAY(), update your measure like this

     

    MTD = 
    TOTALMTD ( 
    SUM ( 'MTD'[RecordAmount] ),  
    CALCULATETABLE ( VALUES ( 'Calendar'[Date] ),  'Calendar'[Date] <= TODAY() ) 
    )

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • Hi,

    To your visual, if you have dragged year and Month name from the Date Table, then you need not write seperate measures for the MTD.  MTD should be TotalCount and Totalvalue measures itself.