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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
charonT
Helper I
Helper I

Calculate YoY Change if applied a Year filter

Hi I am writing a DAX to calculate a YoY Change. Since the year is applied as a filter, when I select the current year, the power bi will not return the data from the year before. Here is the DAX I am working with:

 

YoY_change =
VAR CurYear = SELECTEDVALUE('Year'[Year])
VAR PO_CurYear =
    DIVIDE(
        SUMX(
            FILTER('PO', 'PO'[Year] = CurYear),
            'PO'[Numerator]
        ),
        SUMX(
            FILTER('PO', 'PO'[Year] = CurYear),
            'PO'[Denominator]
        )
    )
VAR PreYear = CurYear - 1
VAR PO_PreYear =
    DIVIDE(
        calculate(SUM('PO'[Numerator]),
            FILTER(All('PO'[Year]), 'PO'[Year] = PreYear)            
        ),
        calculate(SUM('PO'[Denominator]),
            FILTER('PO', 'PO'[Year] = PreYear)            
        )
    )
RETURN
    PO_CurYear - PO_PreYear
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @charonT ,

I suggest that you create a new table (without any relationship to the original table) with only the years that need to be selected, and then use this new table to create the slicer. And use "ALLSELECTED" in your DAX.
Since you didn't provide the data, I can only provide you with an example of how to implement it.
Here is my sample data:

vjunyantmsft_0-1706146678519.png

I add a new table for creating a slicer for year:

vjunyantmsft_1-1706146724338.png
vjunyantmsft_2-1706146732398.png

Then I use these DAXs to create measures:

CurrentYear = 
CALCULATE(
    SUM(Sheet16[sales]),
    YEAR('Sheet16'[date]) = SELECTEDVALUE(Slicer[Year]) && 'Sheet16'[weeknumber] = SELECTEDVALUE(Sheet16[weeknumber]) && 'Sheet16'[country] = SELECTEDVALUE(Sheet16[country]),
    ALLSELECTED(Sheet16)
)
PreviousYear = 
CALCULATE(
    SUM(Sheet16[sales]),
    YEAR('Sheet16'[date]) = SELECTEDVALUE(Slicer[Year]) - 1 && 'Sheet16'[weeknumber] = SELECTEDVALUE(Sheet16[weeknumber]) && 'Sheet16'[country] = SELECTEDVALUE(Sheet16[country]),
    ALLSELECTED(Sheet16)
)

The final output is like below:

vjunyantmsft_3-1706146817623.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
charonT
Helper I
Helper I

Thank you, I resolved it by myself in the end.

Following a similar approach to the reply, I added two columns, "last_num" and "last_den," and used VLOOKUP to add the data from the previous year into these columns.

While this is not the ideal solution as I intended to maintain the data structure and model as simple as possible, it still serves as a resolution.

Anonymous
Not applicable

Hi @charonT ,

I suggest that you create a new table (without any relationship to the original table) with only the years that need to be selected, and then use this new table to create the slicer. And use "ALLSELECTED" in your DAX.
Since you didn't provide the data, I can only provide you with an example of how to implement it.
Here is my sample data:

vjunyantmsft_0-1706146678519.png

I add a new table for creating a slicer for year:

vjunyantmsft_1-1706146724338.png
vjunyantmsft_2-1706146732398.png

Then I use these DAXs to create measures:

CurrentYear = 
CALCULATE(
    SUM(Sheet16[sales]),
    YEAR('Sheet16'[date]) = SELECTEDVALUE(Slicer[Year]) && 'Sheet16'[weeknumber] = SELECTEDVALUE(Sheet16[weeknumber]) && 'Sheet16'[country] = SELECTEDVALUE(Sheet16[country]),
    ALLSELECTED(Sheet16)
)
PreviousYear = 
CALCULATE(
    SUM(Sheet16[sales]),
    YEAR('Sheet16'[date]) = SELECTEDVALUE(Slicer[Year]) - 1 && 'Sheet16'[weeknumber] = SELECTEDVALUE(Sheet16[weeknumber]) && 'Sheet16'[country] = SELECTEDVALUE(Sheet16[country]),
    ALLSELECTED(Sheet16)
)

The final output is like below:

vjunyantmsft_3-1706146817623.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors