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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bryanc78
Helper IV
Helper IV

Dax help - measure to show % of passed items by category

I have a clustered stacked chart in excel I use to trend test improvements over the last few months.  For example, the % of question 1 being passed will show for april, may and june.  Then the same for question 2 and so on.

 

PBI doesn't support that but it looks like their stacked % chart will get me close.  Problem is, % is for all of the questions and not just for one category at a time

 

Below is how my columns look in PBI and I would like the stacked % bar chart to show that question 1 is 75% as that is the percentage of the question being passed.  The next section of the bar would be for question 2 and that would show 50%.  Then I can have a 1 column for each month and I can compare improvements that way.

 

This possible?

image.png

 

1 ACCEPTED SOLUTION

That is caused by the fact that if either argument to the divide function returns a blank, the result of the divide will be blank. One fix for ths is to check if the count of all scores is greater than 0 then add a hard 0 to the count of passed scores.

eg

Pass % = 
VAR _allScoresCnt = CALCULATE(COUNTROWS(Table1),ALL(Table1[Score]))
VAR _passCnt = CALCULATE(COUNTROWS(Table1), Table1[Score] = "Pass") + IF(_allScoresCnt > 0,0)
return DIVIDE(_passCnt, _allScoresCnt)

View solution in original post

5 REPLIES 5
d_gosbell
Super User
Super User

You should be able to do this with a measure like the following

Pass % = 
VAR _passCnt = CALCULATE(COUNTROWS(Table1), Table1[Score] = "Pass")
VAR _allScoresCnt = CALCULATE(COUNTROWS(Table1),ALL(Table1[Score]))
return DIVIDE(_passCnt, _allScoresCnt)

Then simply create a normal stacked column chart and put this measure on the values and the questions on the Axis

 


@bryanc78 wrote:

PBI doesn't support that but it looks like their stacked % chart will get me close. 


I don't really understand what you are trying to achieve. If you can post an image of the output maybe the same chart exists in Power BI but just has a different name.

This is close but on one of my questions, I don't have any that have passed. Instead of showing 0%, the question is not even showing at all

That is caused by the fact that if either argument to the divide function returns a blank, the result of the divide will be blank. One fix for ths is to check if the count of all scores is greater than 0 then add a hard 0 to the count of passed scores.

eg

Pass % = 
VAR _allScoresCnt = CALCULATE(COUNTROWS(Table1),ALL(Table1[Score]))
VAR _passCnt = CALCULATE(COUNTROWS(Table1), Table1[Score] = "Pass") + IF(_allScoresCnt > 0,0)
return DIVIDE(_passCnt, _allScoresCnt)

That worked, thank you.

Do you know if any resources that would good to start learning DAX?

My friends over at sqlbi.com have a stack of great resources. They wrote a book called "The Definitive Guide to DAX" and the also have videos and run training courses and have a number of articles on their site. And there is a list of a number of great DAX resources here: https://social.technet.microsoft.com/wiki/contents/articles/1088.dax-resource-center.aspx

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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