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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
vonw13
Frequent Visitor

Sameperiodlastyear showing entire month instead of mtd

I used a measure to take the total sales mtd, then a new measure to use sameperiodlast year, but it shows the full month of May 2021 instead of mtd previous year. How do I get it do accuratlely show through mtd previous year? I have slicers on my report for month and year.

 

Sales data PY using manual slicers

vonw13_0-1652728694272.png

 

Current year MTD showing accurately

vonw13_1-1652728749304.png

 

PY MTD showing entire month

 

vonw13_2-1652728784670.png

 

 

1 ACCEPTED SOLUTION
themistoklis
Community Champion
Community Champion

Hello @vonw13 

 

Try the following formula. Make sure you have a calendar table.

 

Turnover MTD (PY) = CALCULATE(SUM('Table'[TurnOver]),
        DATESBETWEEN('Calendar'[Date],                    
            FIRSTDATE(DATEADD('Calendar'[Date],-12,MONTH)),   
            IF(MONTH(MIN('Calendar'[Date])) = MONTH(TODAY()), EDATE(TODAY(),-12) , LASTDATE(DATEADD('Calendar'[Date],-12,MONTH))) 
         )
     )

 

View solution in original post

4 REPLIES 4
themistoklis
Community Champion
Community Champion

Hello @vonw13 

 

Try the following formula. Make sure you have a calendar table.

 

Turnover MTD (PY) = CALCULATE(SUM('Table'[TurnOver]),
        DATESBETWEEN('Calendar'[Date],                    
            FIRSTDATE(DATEADD('Calendar'[Date],-12,MONTH)),   
            IF(MONTH(MIN('Calendar'[Date])) = MONTH(TODAY()), EDATE(TODAY(),-12) , LASTDATE(DATEADD('Calendar'[Date],-12,MONTH))) 
         )
     )

 

That worked! Thank you so much! Do you know why just the regular sameperiodlast year or the other functions didn't work?

To be honest I dont know the answer to this question. 

There are alternatives on calculating the MTD for previous year but I found the above formula the one that covered my needs.

 

May worth trying the formula from this post as well.

https://community.powerbi.com/t5/Desktop/MTD-Comparison-to-same-period-last-year/m-p/188900

 

speedramps
Super User
Super User

Please watch this series of free BI training videos inlcuding a free calendar download.

Then you can sum, filters and compare MTD, YTD, LM, LY, ect like a rock star.

Click here for free videos 

 

Please click thumbs up and accept as solution. 😀

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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