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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Inspection Dataset Measures

I have an inspection dataset similar to the below.

 

IDDateResult
101/01/2022Pass
102/01/2022Fail
201/01/2022Pass
202/01/2022Pass
203/01/2022Fail

 

I want to create a measure which can track the following:

 

  1. Looking at individual ID's, I want to track the average time it takes to Fail after recieving a Pass as the first result

  2. Count of distinct ID's that only ever recieve a Pass
  3. Count of distinct ID's that recieve a Pass as their first result then a Fail any time after the first Pass

 

Many thanks 🙂 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I modify these measures, please try them:

 

Datediff = 
VAR startdate =
    CALCULATE ( MIN ( 'Table'[Date] ), 'Table'[Result] = "Pass" )
VAR enddate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        'Table'[Result] = "Fail",
        'Table'[Date] >= startdate
    )
RETURN
    DATEDIFF ( startdate, enddate, DAY ) + 0
Total recieve Pass then Fail = SUMX ( VALUES ( 'Table'[ID] ), [recieve Pass then Fail] )

vkkfmsft_0-1651225337985.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

5 REPLIES 5
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try the following formula:

 

Datediff = 
VAR startdate =
    CALCULATE ( MIN ( 'Table'[Date] ), 'Table'[Result] = "Pass" )
VAR enddate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        'Table'[Result] = "Fail",
        'Table'[Date] >= startdate
    )
RETURN
    DATEDIFF ( startdate, enddate, DAY )
Average time = AVERAGEX ( VALUES ( 'Table'[ID] ), [Datediff] )
CountResultPerID = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Result] ),
    ALLEXCEPT ( 'Table', 'Table'[ID] )
)
only recieve Pass = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[ID] ),
    FILTER ( 'Table', 'Table'[Result] = "Pass" && [CountResultPerID] = 1 )
)
recieve Pass then Fail =
VAR Firstday =
    CALCULATE ( MIN ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        FILTER (
            'Table',
            'Table'[Date] = Firstday
                && 'Table'[Result] = "Pass"
                && [CountResultPerID] = 2
        )
    )

vkkfmsft_0-1651029437241.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi,

 

Thanks for your response. I have added all measures into my PBIX file and are recieving some errors.

 

Looking at ID 1796 in particalar I have the below data.

IDDateResult
179615/12/2021Pass
179608/12/2021Pass
179601/12/2021Pass
179624/11/2021Pass
179617/11/2021Pass
179610/11/2021Pass
179603/11/2021Pass
179627/10/2021Pass
179620/10/2021Pass
179613/10/2021Pass
179606/10/2021Pass
179629/09/2021Pass
179622/09/2021Pass
179615/09/2021Pass
179608/09/2021Pass
179601/09/2021Pass
179625/08/2021Fail

 

I am seeing the below results which is not correct as this specific ID has a fail.

 

Serdet_0-1651047700597.png

Any ideas?

Hi @Anonymous ,

 

I modify these measures, please try them:

 

Datediff = 
VAR startdate =
    CALCULATE ( MIN ( 'Table'[Date] ), 'Table'[Result] = "Pass" )
VAR enddate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        'Table'[Result] = "Fail",
        'Table'[Date] >= startdate
    )
RETURN
    DATEDIFF ( startdate, enddate, DAY ) + 0
Total recieve Pass then Fail = SUMX ( VALUES ( 'Table'[ID] ), [recieve Pass then Fail] )

vkkfmsft_0-1651225337985.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. Your scenario 2 is not covered.

Please show the expected outcome based on the sample data you provided.

Anonymous
Not applicable

Hi,

 

Thanks for your response. Unfortunetely due to company confidentity I can only supply a sample dataset.

 

IDDateResult
101/01/2022Pass
102/01/2022Fail
201/01/2022Pass
202/01/2022Pass
203/01/2022Fail
301/02/2022Pass

 

Based upon the above dataset I would see the below outcomes for each scenario.

 

1. Average time it takes to fail after recieving a pass as the first result = 1.5 days

2. Count of distinct ID's that only ever recieve a Pass = 1 

3. Count of distinct ID's that recieve a Pass as their first result then a Fail any time after the first Pass = 2

 

Hope this helps.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.