Forum Discussion

gorsheep's avatar
gorsheep
Regular Visitor
4 years ago
Solved

Matrix - change level of column headers

I have some data that is structured in a way shown in Fig. 1. My goal is to create a pivot table (using Matrix) that looks like one I created in Excel (see Fig. 2.). However, in Power BI I get a matrix in which years have the upper level, and my variables have a lower level (see Fig.  3). How do I change the level of years and my variables?

 

Fig. 1:

 

Fig. 2:

 

Fig. 3:

   

  • Hi gorsheep ,

     

    You need unpivot the underlying table in power query firstly.

    And create measure as the following code:

    Measure =
    IF (
        SELECTEDVALUE ( 'Table'[Attribute] ) = "Margin",
        FORMAT ( SUM ( 'Table'[Value] ), "#%" ),
        FORMAT ( SUM ( 'Table'[Value] ), "#" )
    )
    

    Visualization pane:

    Result:

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    Icon for Community Support rankCommunity Support

    Hi gorsheep ,

     

    You need unpivot the underlying table in power query firstly.

    And create measure as the following code:

    Measure =
    IF (
        SELECTEDVALUE ( 'Table'[Attribute] ) = "Margin",
        FORMAT ( SUM ( 'Table'[Value] ), "#%" ),
        FORMAT ( SUM ( 'Table'[Value] ), "#" )
    )
    

    Visualization pane:

    Result:

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Seanan's avatar
    Seanan
    Icon for Solution Supplier rankSolution Supplier

    Hi gorsheep 

    Could you please send a picture of the visualisations pane, showing the rows, columns and values? If you move the column for the sales/margins above the year it should move your variables to the upper level.

  • gorsheep's avatar
    gorsheep
    Regular Visitor

    Hi! Below is a screenshot of the current setup, which yields a table shown in Fig. 3 of the original post. If I move "Year" to the "Values" pane, it just removes the second level of the header.

     

    • Seanan's avatar
      Seanan
      Icon for Solution Supplier rankSolution Supplier

      Hi gorsheep 

      I've been playing around with a matrix in my own envrionment and unfortunately I've been unable to achieve the result you are looking for. Apologies, it may not be possible but maybe someone else will be able to help.