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
PhillipC1
Helper I
Helper I

Dax Formula to get clean stop rate

Hello,

 

I am trying to figure out the dax formula to utilize to obtain a clean stop rate which is number of violations divided by number of inspections. The kicker is that one inspection could have more than one violation which is where I am running into my problem. In the table below, I show some sample data where there are a total of three inspections (Distinct Report Numbers) and two violations (Violation_Count) belonging to the same inspection. In the formula I only want one violation per inspection to be counted if applicable. 

 

This is my current dax formula:

 

Clean Stop Rate = 1-CALCULATE(DIVIDE(SUM('CSA Extract'[VIOLATION_COUNT]),DISTINCTCOUNT('CSA Extract'[REPORT_NUMBER])))

 

 

This is the table for the data:

IDREPORT_NUMBERINSPECTION_RESULTBASICCATEGORYINSPECTION_DATEPOST_DATEVIOLATION_COUNT
729896FYD0XBXFYViolationVehicle MaintenanceTires11/11/202211/22/20221
729896FYD0XBXFYViolationVehicle MaintenanceGeneral Securement11/11/202211/22/20221
729896C2B0XCHLGClean  6/24/20226/28/20220
729896DWE0XJSUEClean  8/29/20229/1/20220

 

My problem is that with that DAX formula, I am returning a result of 33% when I actually need to return 66% as the formula should be more along the lines of below:

 

3 Inspections Total

2 Inspections = Clean

1 Insepction = Violation

 

Meaning that 2 clean inspections divded by 3 total inspections would equal 66.66%

 

I feel like I am just missing something and maybe my brain is fried from the development on this dashboard, but figured I would reach out to see if anyone has a solution. 

1 ACCEPTED SOLUTION
JamesFR06
Resolver IV
Resolver IV

HI

 

var Clean=calculate(DISTINCTCOUNT('CSA Extract'[REPORT_NUMBER]),'CSA Extract'[INSPECTION_RESULT]="Clean")

var _Ttlinspections = calculate(DISTINCTCOUNT('CSA Extract'[REPORT_NUMBER]),all(CSA Extract))

return

divide(Clean,_Ttlinspections)

View solution in original post

2 REPLIES 2
JamesFR06
Resolver IV
Resolver IV

HI

 

var Clean=calculate(DISTINCTCOUNT('CSA Extract'[REPORT_NUMBER]),'CSA Extract'[INSPECTION_RESULT]="Clean")

var _Ttlinspections = calculate(DISTINCTCOUNT('CSA Extract'[REPORT_NUMBER]),all(CSA Extract))

return

divide(Clean,_Ttlinspections)

Awesome, that did it! Thank you so much for that. 

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.