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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
MartianCactus
Regular Visitor

How to unpivot specific columns of the table using DAX?

Untitled.png

Hey, so a novice here. I dont want the data to be leaked so I have hidden it and marked it with tags though.

 

Basically what you are looking at is the accuracy data of a classification model. As you can see, for some classes like "A" it predicts all data points correctly, thus it is flagged as True, but we dont have a False column for A because there are no False values. For some reason when we created this table in DAX by grouping a couple of columns and performing the count operation on different table,DAX didnt show False for any values that were completely True.

On the other hand, for "D", 185 values are true and 2 values are false.

 

We need to showcase this as like a bar chart with maybe a slicer for the different categories. For that we first need the "False" attribute for the values that predicted completely true, then we need to compute the percentage of False and True predictions for each class and then we need to show that in a bar chart.

 

We are thinking we should pivot the "FLAG" and the "Predicted Values" column for this, and then we will be able to do all the things aforementioned. But because this table was created using DAX from another table, we are unable to find a way to pivot it. It wont evens how up in the Power Query editor. Any tips or help are welcomed. Sorry again, Im a novice so just learning as I work..

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Unless I'm misunderstanding your request, the data structure you have should work as it is.

Following Best Practices, I've created dimension tables for flag and category. The main table (fTable in my example) has the structure you  posted.

model.png

 and with the following measures:

Sum P Values = 
SUM(fTable[Predicted Values])
% over Category = 
VAR _CategoryTotal = CALCULATE([Sum P Values], ALL('Dim Flag'[Flag]))
RETURN
DIVIDE([Sum P Values], _CategoryTotal)

Use the field from Dim category as the slicer and the filed from the Dim Flag for the x -axis, to get:

Test.gif

 

I've attached the 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.






View solution in original post

2 REPLIES 2
PaulDBrown
Community Champion
Community Champion

Unless I'm misunderstanding your request, the data structure you have should work as it is.

Following Best Practices, I've created dimension tables for flag and category. The main table (fTable in my example) has the structure you  posted.

model.png

 and with the following measures:

Sum P Values = 
SUM(fTable[Predicted Values])
% over Category = 
VAR _CategoryTotal = CALCULATE([Sum P Values], ALL('Dim Flag'[Flag]))
RETURN
DIVIDE([Sum P Values], _CategoryTotal)

Use the field from Dim category as the slicer and the filed from the Dim Flag for the x -axis, to get:

Test.gif

 

I've attached the 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.






Thanks a ton!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.