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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

MTD LY using Month as Filter Context

Hi,

 

I want to use month as filter conext for my table in power pivot and compare MTD sales TY vs MTD sales last year. For example today is Feb 8 and I want to show MTD sales for this year (currently using SUM(sales) and month as the filter context as my calendar table updates only to the max sales date). Where I am running into issues is MTD LY as it is totaling the whole month of last year (not to Feb 8, 2019). I do not want to put individual dates on the table to solve for this. Any help would be appreciated. 

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please use the below formula :

 

SAME PERIOD LAST YEAR  = 
VAR DataMaxDate =
    CALCULATE ( MAX ( 'Table'[Date.Date].[Date] ), ALL ('Table' ) )
RETURN
    CALCULATE (
        [YTD Sales],
        SAMEPERIODLASTYEAR (
            INTERSECT (
                VALUES ('Table'[Date.Date].[Date] ),
                DATESBETWEEN ( 'Table'[Date.Date], BLANK (), DataMaxDate )
            )
        )
    )

 

 

 

NOTE : make sure to change Date column to date type otherwise you will end up with the same issue you are facing.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.

 

Regards,

Gaurav Raj Singh

LinkedIN : https://www.linkedin.com/in/gauravrajsingh/

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

Please use the below formula :

 

SAME PERIOD LAST YEAR  = 
VAR DataMaxDate =
    CALCULATE ( MAX ( 'Table'[Date.Date].[Date] ), ALL ('Table' ) )
RETURN
    CALCULATE (
        [YTD Sales],
        SAMEPERIODLASTYEAR (
            INTERSECT (
                VALUES ('Table'[Date.Date].[Date] ),
                DATESBETWEEN ( 'Table'[Date.Date], BLANK (), DataMaxDate )
            )
        )
    )

 

 

 

NOTE : make sure to change Date column to date type otherwise you will end up with the same issue you are facing.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.

 

Regards,

Gaurav Raj Singh

LinkedIN : https://www.linkedin.com/in/gauravrajsingh/

Anonymous
Not applicable

Thanks! That worked!

amitchandak
Super User
Super User

Try a filter of day

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)), day('Date'[Date])<=day(today()))

I have not tested it.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
MattAllington
Community Champion
Community Champion

Yes, that's how it works and yes it can be frustrating. The month in your filter is actually using the last day of the month in the filter context (from the calendar table) hence the problem. You need a way to detect the last date with sales in the current month. I like to do this with a calculated column in the calendar table. You could call it something like "Past Date" and return true or false. If you then filter on this column, the calendar filter context will crab the last date with sales, and that should fix the last year data. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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