Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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 🙂 

  • 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] )

     

    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.

5 Replies

  • 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's avatar
      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.

  • v-kkf-msft's avatar
    v-kkf-msft
    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
            )
        )

     

    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's avatar
      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.

       

      Any ideas?

      • v-kkf-msft's avatar
        v-kkf-msft
        Community Support

        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] )

         

        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.