Forum Discussion
% 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])
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?
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.
10 Replies
- ribisht17Super User
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- owenvFrequent Visitor
Thanks for the input. Unfortunately it hasn't solved the situation
- ribisht17Super User
- owenvFrequent Visitor
The below is an anonymised example. I'd expect to see 50% returned for each vehicle with these values.
vehicle pass vehicle 1 TRUE vehicle 2 FALSE vehicle 3 TRUE vehicle 1 FALSE vehicle 2 TRUE vehicle 3 FALSE - Ashish_MathurSuper User
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.
- ribisht17Super User
This should work >>>
Step 1
Total Vehicle = COUNTX(ALL(Vehicle), Vehicle[vehicle])Step 2Total Pass Vehicle = CALCULATE(count(Vehicle[Total Vehicle]),FILTER(all(Vehicle),Vehicle[pass]=true()))Step3Final % = [Total Pass Vehicle]/min(Vehicle[Total Vehicle])*100Regards,RiteshMark 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 - ribisht17Super User
Hope this satisfies your requirement, if yes, kindly mark the answer as correct so that it can help others as well
Regards,RiteshMark 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