cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

DAX Calculation for Year over Year Analysis

So I currently have a formula that determines the year over year % change. However, in my dataset, the following years are used:
2019, 2021, 2022, 2023. The formula works perfectly for all the years except the 2019-2021 change. How could I modify the below formula to calculate the change from 2019-2021 instead of 2020-2021. In other words, how can I make the DAX ignore a year if there is no data for that year. Below is the formula I am using. Thanks in advance! 
 
YoY Expense =
VAR PreviousYearExpense =
    CALCULATE([Expense], DATEADD('Calendar'[Date],-1,YEAR))
RETURN
    DIVIDE(([Expense]-PreviousYearExpense),PreviousYearExpense)
2 REPLIES 2
FreemanZ
Community Champion
Community Champion

hi @Anonymous 

try like:

YoY Expense =
VAR CurrentYear =
SELECTEDVALUE('Calendar'[Year])
VAR PreviousYear =
MAXX(
    FILTER(
        ALL(FactTable),
        YEAR(FactTable[Date])<CurrentYear
    ),
    YEAR(FactTable[Date])
)
VAR PreviousYearExpense =
CALCULATE(
     [Expense], 
     'Calendar'[Year] = PreviousYear)
)
RETURN
DIVIDE(([Expense]-PreviousYearExpense),PreviousYearExpense)
Anonymous
Not applicable

Sorry if this is a dumb question, but what is a FactTable and how do I create one?

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors