Reply
MVenables
Advocate II
Advocate II

Help with Prior Year

Hi all,

 

We currently use a prior year Dax that is shown below. We do not use a normal Calendar as we use a financial Calendar for our business, so when we want to see Prior year sales for example we calculate this by using [AFBYearWeek]. 

The issue we have is the DAX below calculates backwards 100 rows so when we drill down to product level, it is over calculating then crashing, sometimes taking over an hour to load a table with data in.

 

Any suggestions on a better measure would be greatful as this was given to us by an external company and has caused us issues ever since.

SUMX (

    SUMMARIZE (

        'Calendar',

        'Calendar'[AFBYearWeek],

        "PYWS",

            CALCULATE (

                IFERROR ( ( SUM ( Sales_StoreProductDate[SalesValue] ) ), 0 ),

                FILTER (

                    ALL ( 'Calendar' ),

                    'calendar'[AFBYearWeek]

                        = MAX ( 'Calendar'[AFBYearWeek] ) - 100

                )

            )

    ),

    [PYWS]

)



1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@MVenables , It looks like the DAX measure you are using is causing performance issues due to the way it calculates the prior year sales by iterating over 100 rows.

Instead of calculating the prior year week dynamically in your measure, you can create a calculated column in your 'Calendar' table that stores the prior year week. This will make your measure more efficient.

 

PriorYearWeek = 'Calendar'[AFBYearWeek] - 100

 

Then you can use this calculated column in your measure

PriorYearSales =
CALCULATE(
SUM(Sales_StoreProductDate[SalesValue]),
FILTER(
ALL('Calendar'),
'Calendar'[AFBYearWeek] = MAX('Calendar'[PriorYearWeek])
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

2 REPLIES 2
bhanu_gautam
Super User
Super User

@MVenables , It looks like the DAX measure you are using is causing performance issues due to the way it calculates the prior year sales by iterating over 100 rows.

Instead of calculating the prior year week dynamically in your measure, you can create a calculated column in your 'Calendar' table that stores the prior year week. This will make your measure more efficient.

 

PriorYearWeek = 'Calendar'[AFBYearWeek] - 100

 

Then you can use this calculated column in your measure

PriorYearSales =
CALCULATE(
SUM(Sales_StoreProductDate[SalesValue]),
FILTER(
ALL('Calendar'),
'Calendar'[AFBYearWeek] = MAX('Calendar'[PriorYearWeek])
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi Bhanu, Thank you for this suggestion, we have done some initial testing so far against what we had before and it does seem much better. The external company who created the original formula did something similar to what you suggested on Friday, but they are still using SUMX, so like you say i believe that is the main issue with this. Appreciate the help on this as i believe with more testing we will be using this within the business at some point.

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)