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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Katie123
New Member

Creating a table with metrics in rows and calc'd in columns

Katie123_1-1635359139008.png

 

I am looking to create a table that looks like the above. I can create the metrics but I can only get it to display as all columns or all rows. I can't figure out if there's a way to make some metrics rows and other columns. Any help is appreciated.

 

5 REPLIES 5
PaulDBrown
Community Champion
Community Champion

Are the year values to remain static or do you need them to be dynamic? (For example current year and previous year)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






They would remain static - though I have more than this year and last year date attributes I could create tables for the various views as needed

Here is one way. 

Please bear in mind this exampe is built on a simple fact table. You will need to adapt the measures and tables to suit your model

1) create a new independent table for the Years and Diff using:

Table.JPGIndex.JPG

2) Create the measures for each value using the following syntax :

 

Volume =
VAR MX =
    CALCULATE (
        MAX ( 'Columns Table'[Column] ),
        FILTER (
            ALLSELECTED ( 'Columns Table'[Column] ),
            'Columns Table'[Column] <> "Diff"
        )
    )
VAR MinY =
    CALCULATE (
        MIN ( 'Columns Table'[Column] ),
        FILTER (
            ALLSELECTED ( 'Columns Table'[Column] ),
            'Columns Table'[Column] <> "Diff"
        )
    )
VAR MAXYC =
    CALCULATE (
        SUM ( FactTable[Volume] ),
        FORMAT ( FactTable[Year], "General Number" ) = MX
    )
VAR MINYC =
    CALCULATE (
        SUM ( FactTable[Volume] ),
        FORMAT ( FactTable[Year], "General Number" ) = MinY
    )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Columns Table'[Column] ),
        MX, MAXYC,
        MinY, MINYC,
        MAXYC - MINYC
    )

 

3) Create a matrix visual and add the columns table field to the columns bucket and add each measure to the values bucket.

Column.gif

 

In the formatting pane, under Values, turn on the option "Show on Rows":

rows.JPG

Select the visual and set the required values in the filter pane:

Filter.JPG

 

And this is the result:

reslt.JPG

 

I've attached a sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






v-janeyg-msft
Community Support
Community Support

Hi, @Katie123 

 

According to your description, I think you can create a Dax table using DATATABLE() function. The syntax allows you to define each column name and data type, and then add data values to it. 

Like this:

Table =
DATATABLE (
    " ", STRING,
    "2020", INTEGER,
    "2021", INTEGER,
    "Diff", INTEGER,
    {
        { "Volume", 100, 300, 200 },
        { "Sales", 1000, 1500, 500 },
        { "Cost", 100, 150, 50 },
        { "Margin", 900, 1350, 450 }
    }
)

vjaneygmsft_0-1635756884669.png

Reference:DATATABLE function - DAX | Microsoft Docs

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.


Best Regards,
Community Support Team _ Janey

Kumail
Post Prodigy
Post Prodigy

Hello @Katie123 


If you could send a sample .pbix that demonstrates what you are looking to get. It would really help to provide you with a quick solution.


Regards
Kumail Raza

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.