Forum Discussion

tamiribas's avatar
tamiribas
Resolver I
2 years ago
Solved

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...
  • Anonymous's avatar
    Anonymous
    2 years ago

    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:

    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:

     

    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.



  • tamiribas's avatar
    tamiribas
    2 years ago

    Thank you Anonymous , it looks promising. I will check it out.

    Regards,

    Tamir