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
Moxam
Helper I
Helper I

Calculate Function Does Not Change Filter Context

Hello everyone,

I have a data model that has two tables: Calendar, which a non-standard date table, and Transactions. They are joined by a column called period. The period takes the form of YYYYMM, e.g., 202410. Each row in the Calendar table represents a month. Another column inside Calendar also provides the first day of the month, so the dates are non-contiguous, which rules out the time intelligence functions.

Sales are calculated in a fairly standard way:

Total Sales = CALCULATE(SUM('Transaction'[Sales Amt])).

What I want is to find the sales amount last year as at the same month. When I try:

CALCULATE([Total Sales], Calendar[Period] - 100)

a blank is returned. The minus 100 is supposed to produce: 202310. I have also tried:

CALCULATE([Total Sales], Calendar[Period] = MAX(Calendar[Period]) - 100)

and the issue persists.

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION
danextian
Super User
Super User

hI @Moxam 

 

If you have a start of month in your calendar table, you should still be able to use SAMEPERIODLASTYEAR or you can use EDATE on the current row start of month to go back to x perios prior.

12 Periods Back = 
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        ALL ( 'CalendarTable' ),
        CalendarTable[Start Of Month]
            = EDATE ( MAX ( CalendarTable[Start Of Month] ), -12 )
    )
)
12 Periods Back SAMEPERIODLASTYEAR =
CALCULATE (
    SUM ( 'Table'[Value] ),
    SAMEPERIODLASTYEAR ( CalendarTable[Start Of Month] ),
    REMOVEFILTERS ( CalendarTable )
)

danextian_0-1732590648447.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Why in the first place do you have a non-standard date table?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
danextian
Super User
Super User

hI @Moxam 

 

If you have a start of month in your calendar table, you should still be able to use SAMEPERIODLASTYEAR or you can use EDATE on the current row start of month to go back to x perios prior.

12 Periods Back = 
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        ALL ( 'CalendarTable' ),
        CalendarTable[Start Of Month]
            = EDATE ( MAX ( CalendarTable[Start Of Month] ), -12 )
    )
)
12 Periods Back SAMEPERIODLASTYEAR =
CALCULATE (
    SUM ( 'Table'[Value] ),
    SAMEPERIODLASTYEAR ( CalendarTable[Start Of Month] ),
    REMOVEFILTERS ( CalendarTable )
)

danextian_0-1732590648447.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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