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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
tamiribas
Helper II
Helper II

How to create a Year Difference Column with multiple measures

Hi 

I have a matrix with 2 simple measures across two years:

Total Sum, Total Count 

How can I add a column with Year Over Year Difference?

Below is an Excel example of my desired outcome. I need help creating the Yellow column.

(Years are taken from the dimDate, measures from the factSales)

 

tamiribas_0-1699880303541.png

 

Thank you

Tamir

2 ACCEPTED SOLUTIONS
v-junyant-msft
Community Support
Community Support

Hi @tamiribas ,

I'm sorry I can only do this for the time being, I think maybe this result won't be what you expected. I will continue to try to achieve your desired results exactly.
I'll go through the method I'm using:
You can create a new table using the following DAX:

vjunyantmsft_0-1700036797116.png

SummaryTable = 
VAR SalesAmount2021 = CALCULATE(SUM(factSales[Amount]), 'dimDate'[Year] = 2021)
VAR SalesAmount2022 = CALCULATE(SUM(factSales[Amount]), 'dimDate'[Year] = 2022)
VAR TotalAmount2021 = CALCULATE(COUNTROWS('factSales'), 'dimDate'[Year] = 2021)
VAR TotalAmount2022 = CALCULATE(COUNTROWS('factSales'), 'dimDate'[Year] = 2022)
VAR SalesAmountDiff = SalesAmount2022 - SalesAmount2021
VAR TotalAmountDiff = TotalAmount2022 - TotalAmount2021

RETURN
    UNION(
        ROW("Year", "2021", "SalesAmount", SalesAmount2021, "TotalAmount", TotalAmount2021),
        ROW("Year", "2022", "SalesAmount", SalesAmount2022, "TotalAmount", TotalAmount2022),
        ROW("Year", "YoY", "SalesAmount", SalesAmountDiff, "TotalAmount", TotalAmountDiff)
    )

Then create the matrix with the newly created table:

vjunyantmsft_1-1700036903704.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

Thank you @v-junyant-msft , it looks promising. I will check it out.

Regards,

Tamir

View solution in original post

4 REPLIES 4
v-junyant-msft
Community Support
Community Support

Hi @tamiribas ,

I'm sorry I can only do this for the time being, I think maybe this result won't be what you expected. I will continue to try to achieve your desired results exactly.
I'll go through the method I'm using:
You can create a new table using the following DAX:

vjunyantmsft_0-1700036797116.png

SummaryTable = 
VAR SalesAmount2021 = CALCULATE(SUM(factSales[Amount]), 'dimDate'[Year] = 2021)
VAR SalesAmount2022 = CALCULATE(SUM(factSales[Amount]), 'dimDate'[Year] = 2022)
VAR TotalAmount2021 = CALCULATE(COUNTROWS('factSales'), 'dimDate'[Year] = 2021)
VAR TotalAmount2022 = CALCULATE(COUNTROWS('factSales'), 'dimDate'[Year] = 2022)
VAR SalesAmountDiff = SalesAmount2022 - SalesAmount2021
VAR TotalAmountDiff = TotalAmount2022 - TotalAmount2021

RETURN
    UNION(
        ROW("Year", "2021", "SalesAmount", SalesAmount2021, "TotalAmount", TotalAmount2021),
        ROW("Year", "2022", "SalesAmount", SalesAmount2022, "TotalAmount", TotalAmount2022),
        ROW("Year", "YoY", "SalesAmount", SalesAmountDiff, "TotalAmount", TotalAmountDiff)
    )

Then create the matrix with the newly created table:

vjunyantmsft_1-1700036903704.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.



Thank you @v-junyant-msft , it looks promising. I will check it out.

Regards,

Tamir

tamiribas
Helper II
Helper II

Hi,

Using this measure will indeed give the previous year's amount. However, my challenge is the layout!

If I use the default matrix layout I get the years in the rows and the measure in the columns.

If I activate the "switch values to rows" option I get the measures in the rows and the years in the columns as in the above screenshot.

My need is to show the last measure in the column (same dimensions as the years)

(Link to my demo file)

Tx

Tamir

 

3CloudThomas
Super User
Super User

If you have time intelligence turned on, and a date table related to you sales, you can use the DAX function SAMEPERIODLASTYEAR.

= CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(DateTime[DateKey]))

reference - SAMEPERIODLASTYEAR – DAX Guide

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.