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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Touliloop
Helper I
Helper I

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

7 REPLIES 7
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 @hnguy71 

I have a question, what if I want for when Country = US, I would like the YoY to be 150 - 300 instead of (150 - 300) / 300? I am facing this problem now, tried lotsof things it didn't work...Do you happen to know how to do that?

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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