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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
adventurer7
Helper I
Helper I

Measures to Columns

Hello. I currently have a table in this format :

NameCategory ACategory BCategory C
Name 1001
Name 2101
Name 3111
Name 4100
Name 5010

 

And I have these measures to count the zeroes :

Category A Count = COUNTROWS(FILTER(Table1,Table1[Category A]=0))

Category B Count = COUNTROWS(FILTER(Table1,Table1[Category B]=0))

Category C Count = COUNTROWS(FILTER(Table1,Table1[Category C]=0))

 

And the percentage of zeroes over count of rows :

Category A % = Category A Count/COUNT(Table1[Name])

Category B % = Category B Count/COUNT(Table1[Name])

Category C % = Category C Count/COUNT(Table1[Name])

 

Is there a way to achieve below matrix format without unpivoting the table? I think there should only be one measure for count and one for % but I can't make it work. Thanks in advance!

 

 Count%
Category A240%
Category B360%
Category C240%
1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi, @adventurer7 

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can use dax to unpivot your table, you can click "New Table":

Table 2 = UNION( ADDCOLUMNS( SELECTCOLUMNS('Table',"Value",[Category A],"Name",[Name]) , "Category","Category A"),
ADDCOLUMNS( SELECTCOLUMNS('Table',"Value",[Category B],"Name",[Name]) , "Category","Category B"),
ADDCOLUMNS( SELECTCOLUMNS('Table',"Value",[Category C],"Name",[Name]) , "Category","Category C"))

vyueyunzhmsft_0-1671589900846.png

 

(3)Then we can create two measures:

Count = CALCULATE( COUNT('Table 2'[Value]) , 'Table 2'[Value]=0)
% = DIVIDE([Count], DISTINCTCOUNT('Table 2'[Name]))

(4)Then we can put the measure on the visual and we can meet your need:

vyueyunzhmsft_1-1671589948614.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

View solution in original post

6 REPLIES 6
v-yueyunzh-msft
Community Support
Community Support

Hi, @adventurer7 

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can use dax to unpivot your table, you can click "New Table":

Table 2 = UNION( ADDCOLUMNS( SELECTCOLUMNS('Table',"Value",[Category A],"Name",[Name]) , "Category","Category A"),
ADDCOLUMNS( SELECTCOLUMNS('Table',"Value",[Category B],"Name",[Name]) , "Category","Category B"),
ADDCOLUMNS( SELECTCOLUMNS('Table',"Value",[Category C],"Name",[Name]) , "Category","Category C"))

vyueyunzhmsft_0-1671589900846.png

 

(3)Then we can create two measures:

Count = CALCULATE( COUNT('Table 2'[Value]) , 'Table 2'[Value]=0)
% = DIVIDE([Count], DISTINCTCOUNT('Table 2'[Name]))

(4)Then we can put the measure on the visual and we can meet your need:

vyueyunzhmsft_1-1671589948614.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Works like a charm! Thanks Aniyaaaa appeciate it

bolfri
Super User
Super User

Can you tell us why you don't want to unpivot the data?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi! There are already existing visuals and several columns/measures made using this table format.

Are you suggesting I reference/duplicate the table and unpivot it?

Actually sometimes it's better to rebuild whole dashboard using correct model than trying to find a "workaround" solutions that you will hate in the future. Power BI is super-easy, fast and even if you need to rebuild some stuff it will be much easier, because right know you know what you want.

 

If you want, you can send me a pbix file. I can rebuild it for you. 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@adventurer7 , In the Matrix switch values to row, should do the job

 

of try calculation group

 

Calculation Groups- Measure Slicer, Measure Header Grouping, Measure to dimension conversion. Complex Table display : https://youtu.be/qMNv67P8Go0

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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