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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Touliloop
New Member

Calculate YoY change as a column next to year

I have a dataset as following, for each country and each year and each metric there is only one row.

 

CountryYearCostCustomersOrders
CN202510010150
US20252008060
UK20251501540
CN20242002015
UK202430030100
US20243004090
FR202415010100


I would like to have a matrix, in which Year is the column, beside the Year column is a column "YoY" which calculate the YoY growth of each metric. As row it should ideally shows the name of the metric. Country would be filtered by a slicer. An wished output would be as below, (if a country doesn't have current year or previous year then YoY show as empty) assume we select the country US using the slicer:

 

 20242025YoY
Cost300200-33%
Customers4080100%
Orders9060

-50%

2 ACCEPTED SOLUTIONS

Hi @Touliloop ,

 

Alright. I'm going to assume two things:

 

1. You're not planning on using a Date table.

2. You're going to allow users to elect which year he/she wants to evaluate to analyze the two years.

 

Step 01: Create a table that you can link to your fact table with a custom row for "YoY"'

Years = 

VAR _Years = VALUES('Fact'[Year])
VAR _TotalRow = ROW("Year", "YoY")
RETURN
UNION(_Years, _TotalRow)


Step 02: Connect Year to Year

hnguy71_0-1752701781703.png

 

Step 03: Create a disconnected table to allow your users to select which year they want to evaluate

SelectYears = 

VAR _Years = VALUES('Fact'[Year])
RETURN
_Years


Step 04: Create the year over year measure. Of course, substitute your_base_measure with your actual measure.

YearOverYear = 

VAR _SelectedYear = SELECTEDVALUE(SelectYears[Year], CALCULATE(MAX(SelectYears[Year]), ALL(SelectYears)))
VAR _PreviousYear = _SelectedYear - 1

VAR _YearInContext = SELECTEDVALUE(Years[Year])

RETURN

SWITCH( TRUE(),
    _YearInContext = "YOY", 
        VAR _Current = CALCULATE([YOUR_BASE_MEASURE], ALL(Years), KEEPFILTERS('Fact'[Year] = _SelectedYear))
        VAR _Previous = CALCULATE([YOUR_BASE_MEASURE], ALL(Years), KEEPFILTERS('Fact'[Year] = _PreviousYear))
        RETURN
        DIVIDE(_Current, _Previous),
    [YOUR_BASE_MEASURE]
)

 

Step 05: Adjust your dynamic formatting on the measure

VAR _Year = MAX(Years[Year])
RETURN

SWITCH( TRUE(),
    _Year = "YOY", "0%;-0%;0%",
    "0.00"
)

 

All that's left is to plug all the columns and measures into a matrix like so

hnguy71_1-1752701999313.png

Now, my shown output is different from yours because your sample data doesn't have an attritbute called "Cost" or "Customer", or "Order".  You would have to unpivot your data in order to get that granularity, or alternatively, build a dimesion for these attributes (similar to how we've just created the Year). Your matrix rows and columns cannot be measures.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.  Solved using calcualtion groups

Ashish_Mathur_0-1752907210918.png

 


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

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.  Solved using calcualtion groups

Ashish_Mathur_0-1752907210918.png

 


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

Hi @Touliloop 

Two questions:

1. Will you always be evaluating these three fields?

2. Do you always want to show the year numbers?



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Hi @Touliloop ,

 

Alright. I'm going to assume two things:

 

1. You're not planning on using a Date table.

2. You're going to allow users to elect which year he/she wants to evaluate to analyze the two years.

 

Step 01: Create a table that you can link to your fact table with a custom row for "YoY"'

Years = 

VAR _Years = VALUES('Fact'[Year])
VAR _TotalRow = ROW("Year", "YoY")
RETURN
UNION(_Years, _TotalRow)


Step 02: Connect Year to Year

hnguy71_0-1752701781703.png

 

Step 03: Create a disconnected table to allow your users to select which year they want to evaluate

SelectYears = 

VAR _Years = VALUES('Fact'[Year])
RETURN
_Years


Step 04: Create the year over year measure. Of course, substitute your_base_measure with your actual measure.

YearOverYear = 

VAR _SelectedYear = SELECTEDVALUE(SelectYears[Year], CALCULATE(MAX(SelectYears[Year]), ALL(SelectYears)))
VAR _PreviousYear = _SelectedYear - 1

VAR _YearInContext = SELECTEDVALUE(Years[Year])

RETURN

SWITCH( TRUE(),
    _YearInContext = "YOY", 
        VAR _Current = CALCULATE([YOUR_BASE_MEASURE], ALL(Years), KEEPFILTERS('Fact'[Year] = _SelectedYear))
        VAR _Previous = CALCULATE([YOUR_BASE_MEASURE], ALL(Years), KEEPFILTERS('Fact'[Year] = _PreviousYear))
        RETURN
        DIVIDE(_Current, _Previous),
    [YOUR_BASE_MEASURE]
)

 

Step 05: Adjust your dynamic formatting on the measure

VAR _Year = MAX(Years[Year])
RETURN

SWITCH( TRUE(),
    _Year = "YOY", "0%;-0%;0%",
    "0.00"
)

 

All that's left is to plug all the columns and measures into a matrix like so

hnguy71_1-1752701999313.png

Now, my shown output is different from yours because your sample data doesn't have an attritbute called "Cost" or "Customer", or "Order".  You would have to unpivot your data in order to get that granularity, or alternatively, build a dimesion for these attributes (similar to how we've just created the Year). Your matrix rows and columns cannot be measures.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Hi @Touliloop 

 

Okay, 1 more question before I assist. Do you use a date table by any chance?



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

I do have a date table, however, I didn't connect it with this table since I only have Year in this table.

Hi @hnguy71 

1) yeah I would like to always evalute these three fields. In fact, in reality I have more columns to be evaluated, this is just an example.

2) Yeah I want to have the year showed as columns.

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.