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

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.

Reply
Anonymous
Not applicable

MTD and MTD Last Year in calendar table mark based on date

Hello Folks,

Just I am marking MTD, MTD Last Year and others in Calendar table , using below DAX  and getting correct result but in Last Year MTD calculations giving me full month .

For example like Today 7th 2021 so MTD would be 1-7th Feb of 2021

                     but for Last Year MTD - It should 1-7th Feb2020

Current_Month_LYSM = SWITCH(Dates[Month_Diff],0,"CM",1,"LM",12,"LYSM","Other Months")

 

I dont have to use any measure like TotalMTD(sum(sales))) like this.

I have to idicate based on Dates.

 

Thanks

 

1 REPLY 1
lbendlin
Super User
Super User

That is by design. You need to add a column in your Dates table that flags all the days that are one year older or more than today (or one month older etc depending on what you compare), and then you need to add that flag as a filter in the calculation

 

Something like

 

Previous Year To Date = 

calculate(something something, SAMEPERIODLASTYEAR(sales[date]),dates[isinpreviouspast]=TRUE())

 

Note that I said column, so this assumes that you are refreshing your dataset daily.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors