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
ciken
Resolver I
Resolver I

Compare MTD to same period last year

Trying to build out a MTD table that will show me how I am doing through the current day in the current month vs the exact same time frame last year (i.e. August 1-10, 2020 vs August 1-10, 2019). When I write my DAX, no matter how many different ways I try, I end up with the full month of August 2019 in comparison and I cannot figure out how to make it only show me the specific dates I'm looking for.  I am positive (as you'll see below) my company did not seel $1m in revenue during the first 10 day so August 2019. Below are my DAX formulas and a screen shot of my table. I've tried SAMEPERIODLASTYEAR which also does not work. Any thoughts are appreciated!!

 

Thanks for the help!

 

MTD Sales = CALCULATE([Total Revenue],DATESMTD('Calendar'[Date]))
SALES LY = CALCULATE([Total Revenue],DATEADD('Calendar'[Date],-1,YEAR))
MTD Last Year = CALCULATE([SALES LY],DATESMTD('Calendar'[Date]))
 Dax Question.png
1 ACCEPTED SOLUTION

@ciken sorry here is the measure for the last year, using the existing measure I shared with you

 

Revenue MTD PY = 
VAR __today = TODAY()
VAR __lastYear = EDATE ( __today, -12 )
RETURN
CALCULATE (
    [Revenue MTD],
    SAMEPERIODLASTYEAR ( 'Dim Calendar'[Date] ),
    'Dim Calendar'[Date] <= __lastYear
)

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@ciken , Try like

MTD QTY forced= 
var _max = today()
return
calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),'Date'[Date]<=_max)


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

 

This happen when you view by month year, for last year it gets the month end date.

@ciken sorry here is the measure for the last year, using the existing measure I shared with you

 

Revenue MTD PY = 
VAR __today = TODAY()
VAR __lastYear = EDATE ( __today, -12 )
RETURN
CALCULATE (
    [Revenue MTD],
    SAMEPERIODLASTYEAR ( 'Dim Calendar'[Date] ),
    'Dim Calendar'[Date] <= __lastYear
)

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

Greg_Deckler
Super User
Super User

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
parry2k
Super User
Super User

@ciken try following measure

 

 

Revenue MTD = 
CALCULATE ( 
    [Total Revenue], 
    DATESMTD ( 
        CALCULATETABLE ( 
            VALUES ( 'Calendar'[Date] ), 
            KEEPFILTERS ( 'Calendar'[Date] <= TODAY() ) 
        )
    ) 
)

 

 

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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 @parry2k , This gave me the MTD for THIS YEAR but not last year. 

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.