Forum Discussion

migueldfr's avatar
migueldfr
Helper IV
1 year ago

Building a Matrix with Asymmetrical Columns and Rows in Power BI

Hello folks,

 

I am sttrugling with this sheet in this small concept

 

I would like to create a pivot table and a bar chart upper which describe the table.

 

Pivot table should contains the values of each quarter in each row and the values for each year in each column. Attached screenshot: 

 

QuarterYearTotal Importe Encargo
Q120221593980
Q12023196626146
Q12024176830989
Q22022159388242
Q22023201556431
Q2202417388848
Q3202217491518
Q32023228064979
Q32024178882189
Q42022166886332
Q42023193844812
Q4202418604966

 

 

I would like to add two more columns into the table in power bi. Which will show up the diference between year(today) - year(today) -1 for each quarter and anothe column with the difference in % (variance

 

This is the plot that I created in first instance.

 



Thank you so much 

I would appreaciatte any help.

 

 

7 Replies

    • migueldfr's avatar
      migueldfr
      Helper IV

      Hello, 

      I am not able to select the one you are talkig about 

       

      Even I tried to add in the preview preliminary but nothing comes out.

       

      Thank you

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi migueldfr ,

    Thanks for ToddChitt's reply!

    And migueldfr , 

    Which will show up the diference between year(today) - year(today) -1 for each quarter and anothe column with the difference in % (variance) 

    Are you trying to calculate the difference between two adjacent years in the same quarter?

    If yes, please try to use these two DAXs to create calculated columns:

    difference = 
    VAR _Year = [Year]
    VAR _Quarter = [Quarter]
    VAR _Current = 
    CALCULATE(
        SUM('Table'[Total Importe Encargo]),
        ALL('Table'),
        'Table'[Year] = _Year && 'Table'[Quarter] = _Quarter
    )
    VAR _Previous = 
    CALCULATE(
        SUM('Table'[Total Importe Encargo]),
        ALL('Table'),
        'Table'[Year] = _Year - 1 && 'Table'[Quarter] = _Quarter
    )
    VAR _MINYear = 
    CALCULATE(
        MIN('Table'[Year]),
        ALL('Table')
    )
    RETURN
    IF(
        'Table'[Year] = _MINYear,
        0,
        _Current - _Previous
    )
    variance = 
    VAR _Year = [Year]
    VAR _Quarter = [Quarter]
    VAR _Currentdifference = [difference]
    VAR _Previous = 
    CALCULATE(
        SUM('Table'[Total Importe Encargo]),
        ALL('Table'),
        'Table'[Year] = _Year - 1 && 'Table'[Quarter] = _Quarter
    )
    VAR _MINYear = 
    CALCULATE(
        MIN('Table'[Year]),
        ALL('Table')
    )
    RETURN
    IF(
        'Table'[Year] = _MINYear,
        0,
        _Currentdifference / _Previous
    )

    And the final output is as below:


    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.

    • migueldfr's avatar
      migueldfr
      Helper IV

      Hello Anonymous 

      thank you for you response. 

      I guess we are close to the result.
      I would like to replicate this table made in excel.



      The point here, is depend on what you are using, if you using if you use pivot table you are gonna see it like this:
      ROWS = QUARTER

      COLUMNS = YEAR

       

      QUARTER202220232024DiferenciaVarianza
      Q11593980196626146176830989  
      Q215938824217491518166886332  
      Q3201556431228064979193844812  
      Q41738884817888218918604966  

      I would appreciate your help 

      Thank you in advance



      • migueldfr's avatar
        migueldfr
        Helper IV

        I keep working and I found another way to approah.

        Building a Matrix with Asymmetrical Columns and Rows in Power BI


        This what I am using.
        I created a table to do it and aslo a measure.

         

        Valores_A_mostrar = 
            VAR Anioseleccionado = VALUE(SELECTEDVALUE(x_Encabezados_tabla[Orden]))  -- Aseguramos que Anioseleccionado es un valor numérico
            VAR AnioActual = YEAR(TODAY())
            VAR ValorAnioActual = CALCULATE([Total Importe Encargo], FILTER('MasterCalendar', 'MasterCalendar'[Year] = AnioActual))
            VAR ValorAnioAnterior = CALCULATE([Total Importe Encargo], FILTER('MasterCalendar', 'MasterCalendar'[Year] = AnioActual - 1))
        
            VAR Diferencia = ValorAnioActual - ValorAnioAnterior
            VAR PorcentajeCambio = DIVIDE(Diferencia, ValorAnioAnterior, 0)
        
            RETURN 
                SWITCH(
                    TRUE(),
                    Anioseleccionado < 5, [Total Importe Encargo], -- Para los valores menores a 5, muestra el Total Importe Encargo
                    Anioseleccionado = 5, Diferencia,  -- Cuando el valor de Orden es 5, muestra la diferencia
                    Anioseleccionado = 6, FORMAT(PorcentajeCambio, "0.00%") -- Cuando el valor de Orden es 6, muestra el porcentaje
                    
                )

         

        But sadly, this does not work as I expected.

        Could anyone give me a hand with this ?

        Thanks

    • migueldfr's avatar
      migueldfr
      Helper IV

      Good afternoon everyone.

      Following the last example I am doing some new features and seem like I am getting there, but sadly I left something.

      I have created a matrix with the Quarter and Years

      Also I added a Total of sales, Difference between Quarters (from each year) and Variance (%) 

      As a final result, I would like to create a Matrix with Year on the top and Quarter on the Left side...

       

      At the moment, I have this:

       

       

      Thank you for any help you could bring to me

      I would appreaciate



  • For the Quarter vs Year matrix with YoY variance columns, the cleanest native approach is using Visual Calculations (available from March 2025 update):

     
     
    YoY Diff = [Sales] - CALCULATE([Sales], PREVIOUSYEAR(DATES))
    YoY % = DIVIDE([YoY Diff], ABS(CALCULATE([Sales], PREVIOUSYEAR(DATES))))

    Visual Calculations run in the visual context so they respect the expand/collapse of your matrix hierarchy automatically no need to write ALLSELECTED or manage filter context manually.

    If your Finance users need to switch which years to compare themselves in the published report (without going back to Desktop), Flexa Tables on AppSource handles this as a built-in button end users select two periods and variance columns appear instantly