Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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.
Solved! Go to Solution.
Hi, @Mohanad-Mustafa
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
@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?
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@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.
✨ Follow us on LinkedIn
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.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. 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?
Hi, @Mohanad-Mustafa
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:-
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |