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
owenv
Frequent Visitor

% based on 2 columns

I have a table of vehicles that have regular inspections. The same vehicle will appear in the table more than once. Sometimes that vehicle will pass an inspection and soemtimes it will fail. I need to calculate the percentage of inspections that result in a pass. It seems like this should be easy but the measure I'm using always returns 100% when I drag the vehicle ID in. The % is correct when I use a basic card that aggregates across the entire table.

 

The (rough) DAX I'm using at the moment:

 

VAR numberOfInspections = COUNTX('inspections', 'inspections'[_index])

RETURN CALCULATE(numberOfInspections, 'inspections'[pass] = TRUE()) / numberOfInspections

This works on a card that doesn't include vehicle names. But if I add a column chart with vehicle IDs, it displays 100% for each vehicle. What am I missing?

 

1 ACCEPTED SOLUTION

Hi,

Try these measures:

Row count = COUNTROWS(Data)
Pass count = CALCULATE([Row count],Data[pass]=TRUE())
Pass % = DIVIDE([Pass count],[Row count])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
ribisht17
Super User
Super User

@owenv 

 

Hope this satisfies your requirement, if yes, kindly mark the answer as correct so that it can help others as well

 

Regards,
Ritesh
Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 
ribisht17
Super User
Super User

@owenv 

This should work >>>

 

Step 1

Total Vehicle = COUNTX(ALL(Vehicle), Vehicle[vehicle])
 
Step 2
Total Pass Vehicle = CALCULATE(count(Vehicle[Total Vehicle]),FILTER(all(Vehicle),Vehicle[pass]=true()))
 
Step3
Final % = [Total Pass Vehicle]/min(Vehicle[Total Vehicle])*100
 
ribisht17_0-1651770038740.png

 

Regards,
Ritesh
Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 
ribisht17
Super User
Super User

@owenv 

 

Please share your table then, hard to solve with this info

 

The below is an anonymised example. I'd expect to see 50% returned for each vehicle with these values.

vehiclepass
vehicle 1TRUE
vehicle 2FALSE
vehicle 3TRUE
vehicle 1FALSE
vehicle 2TRUE
vehicle 3FALSE

 

 

Hi,

Try these measures:

Row count = COUNTROWS(Data)
Pass count = CALCULATE([Row count],Data[pass]=TRUE())
Pass % = DIVIDE([Pass count],[Row count])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Many thanks 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@owenv  , I hope that it helped, if yes, please mark the answer or let us know

 

Ritesh

ribisht17
Super User
Super User

@owenv 

 

Use ALL so that it can come out of the Row Context there .....

Use this DAX = VAR numberOfInspections = COUNTX(ALL('inspections')'inspections'[_index])

 

Regards,

Ritesh

Regards,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

Thanks for the input. Unfortunately it hasn't solved the situation

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.