cancel
Showing results for
Did you mean:

Calculate MTD for 2021, 2020 and 2019

Hi Team,

I have the following MTD measure below that I created in DAX. It works well for 2021 so I just need to have a similar measure that will also display same MTD but for 2020 and 2019. Can you please help me? Thanks a lot, you guys are amazing and rockstars.

MTD = CALCULATE(SUM(Sales[Total Sales]), FILTER('Calendar','Calendar'[Date] >= DATE(YEAR(TODAY()), MONTH(TODAY()), 01)), FILTER('Calendar', 'Calendar'[Date] < TODAY()))

1 ACCEPTED SOLUTION
Community Support

Not clear what you want.

You can try the following formula.

``````MTD2019 =
CALCULATE (
SUM ( Sales[Total Sales] ),
FILTER (
'Calendar',
'Calendar'[Date]
>= DATE ( YEAR ( TODAY () ) - 2, MONTH ( TODAY () ), 01 )
),
FILTER (
' Calendar',
'Calendar'[Date]
< DATE ( YEAR ( TODAY () ) - 2, MONTH ( TODAY () ), DAY ( TODAY () ) )
)
)
``````
``````MTD2020 =
CALCULATE (
SUM ( Sales[Total Sales] ),
FILTER (
'Calendar',
'Calendar'[Date]
>= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), 01 )
),
FILTER (
' Calendar',
'Calendar'[Date]
< DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
)
)
``````

If it doesn't work ,please share a sample file and expected result for further research.

Best Regards,
Community Support Team _ Eason

5 REPLIES 5
Super User

@Mohanad-Mustafa not sure why it wouldn't work. It follows the best practice. Maybe easier if you throw a sample pbix file and I will look into it. Also, I would like to know when you tried the solution used in the video, what didn't work?

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Super User

@Mohanad-Mustafa there are tons of solutions on how to calculated MTD on parallel period or the same period last year, you should use DAX function DATESMTD instead of using the filter function. Here is a video and I hope it is helpful.

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) 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.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks man. I did try this video before and it didn't hep much with the nature of my dataset, do you know a way to create a measure similar to the one I created that will work for 2019 and 2020 please?

Community Support

Not clear what you want.

You can try the following formula.

``````MTD2019 =
CALCULATE (
SUM ( Sales[Total Sales] ),
FILTER (
'Calendar',
'Calendar'[Date]
>= DATE ( YEAR ( TODAY () ) - 2, MONTH ( TODAY () ), 01 )
),
FILTER (
' Calendar',
'Calendar'[Date]
< DATE ( YEAR ( TODAY () ) - 2, MONTH ( TODAY () ), DAY ( TODAY () ) )
)
)
``````
``````MTD2020 =
CALCULATE (
SUM ( Sales[Total Sales] ),
FILTER (
'Calendar',
'Calendar'[Date]
>= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), 01 )
),
FILTER (
' Calendar',
'Calendar'[Date]
< DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
)
)
``````

If it doesn't work ,please share a sample file and expected result for further research.

Best Regards,
Community Support Team _ Eason

Hello Eason, thanks a million man, this works like magic. I only had to tweak the code in MTD2019 and change the -1 to -2 to reflect 2019. MTD2020 worked just fine. Code that worked is below:-

MTD 2019 = CALCULATE ( SUM ( Sales[Total Sales] ), FILTER ( 'Calendar', 'Calendar'[Date] >= DATE ( YEAR ( TODAY () ) - 2, MONTH ( TODAY () ), 01 ) ), FILTER ( 'Calendar', 'Calendar'[Date] < DATE ( YEAR ( TODAY () ) -2, MONTH ( TODAY () ), DAY ( TODAY () ) ) ) )

Announcements

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.