Forum Discussion

konradjonsson's avatar
konradjonsson
Helper II
6 years ago

How to select only first value

I have a table that include the following columns (except the 'Days between failure', which is part of another question).

 

TypeSerial numberSold_DateService_DateFailure time (days)Days between failureProduct
Sales10012010-02-17 00:00   X
Sales10022010-05-28 00:00   X
Service10022010-05-28 00:002013-08-12 00:001172735X
Service10022010-05-28 00:002011-01-19 00:00236236X
Service10022010-05-28 00:002011-05-02 00:00339103X
Service10022010-05-28 00:002011-08-08 00:0043798X
Sales10032010-01-26 00:00   X
Service10032010-01-26 00:002010-07-08 00:00163163X
Service10032010-01-26 00:002012-09-06 00:00954791X
       
   MTTF199,5  
   MTBF 354,3 

 

I want to calculate two different measures - Mean Time To Failure (MTTF) and Mean Time Between Failures (MTBF).

In order to calculate MTTF, I only want to include rows with no failure (e.g. first row above), and rows with the first failure for each Serial number (e.g. row four and row eight above).

In the example, MTTF should be 199.5 (=average(236;163))

My question is - how to extract only the first/earliest service occasion of each unique serial number?

(my own thinking is that I need to create a separate table for this purpose. The original table is used for other purposes, where the sorting order is different)

 

Regards.

 

4 Replies

  • How about adding a calculated column like this? (I named the table "example" and the column "test")

     

    Test =
    VAR FirstSerialDate =
    CALCULATE (
    FIRSTDATE ( Example[Service_Date] ),
    FILTER (
    ALL ( Example ),
    Example[Serial number] = EARLIER ( Example[Serial number] )
    )
    )
    RETURN
    CALCULATE (
    MIN ( Example[Failure time (days)] ),
    Example[Service_Date] = FirstSerialDate
    )
     
     
    If that answer helped may I ask you to mark it as solution and share some kudos :-)
    • konradjonsson's avatar
      konradjonsson
      Helper II

      Hi.

       

      Thank you for the suggestion. I tried it (see formula below) on my dataset. I do however get an error message on the formula.

       

      “A circular dependency was detected: Example[Column],Example[Units with Warranty], Example[Column.”

      The column ‘Units with Warranty’ is a calculated column I made to count the number of units that have had a warranty case.

      Units with Warranty = CALCULATE(

          DISTINCTCOUNT('Example'[Serial_Number]);

          ('Example'[Type]="Warranty")

      )

       

      The reference to ’Example[Column] I assume is generic – there is no column in my dataset with the name ‘Column’.

       

      THE FORMULA

       

      FirstValueOnly =

      VAR FirstSerialDate =

      CALCULATE (

      FIRSTDATE ( Example[Service_Date] );

      FILTER (

      ALL ( Example );

      Example[Serial_Number] = EARLIER ( Example[Serial_Number] )

      )

      )

       

      RETURN

      CALCULATE (

      MIN ( Example[Replacement_Day] );

      Example[Service_Date] = FirstSerialDate

      )

      • konradjonsson's avatar
        konradjonsson
        Helper II

        Hi. I have not been able to find a solution to my problem with any of the suggestions provided so far. That could very well be due to my own shortcomings. I will make another try to explain what I want.

         

        The table below include several warranty transactions for a specific serial number. For my calculations, I only want to keep the first warranty instance. In other words, all the red marked rows should be excluded.

         

        I know how to do this in Excel (sort on serial number, then on warranty date, then chose Data/Remove duplicates). 

        =>how do I do this in Power BI? 


        I do not want to change the original table.

         

        TypeSerial_NumberSold dateWarranty dateReplacement_Day
        New sale1012017-10-25 00:00  
        New sale1022017-10-25 00:00  
        New sale1042017-10-25 00:00  
        Warranty1042017-10-25 00:002018-01-04 00:0071
        New sale1052017-10-26 00:00  
        New sale1062017-10-26 00:00  
        New sale1072017-10-26 00:00  
        Warranty1072017-10-26 00:002018-05-02 00:00188
        Warranty1072017-10-26 00:002018-09-12 00:00321
        New sale1082017-10-27 00:00  
        New sale1092017-10-31 00:00  
        New sale1102017-10-30 00:00  
        New sale1112017-11-01 00:00  
        Warranty1112017-11-01 00:002018-02-20 00:00111
        New sale1122017-11-02 00:00  
        Warranty1122017-11-02 00:002018-01-05 00:0064
        Warranty1122017-11-02 00:002018-01-16 00:0075
        Warranty1122017-11-02 00:002018-01-18 00:0077
        New sale1132017-11-06 00:00  
             
           Average ALL129,6
           Average FIRST INSTANCE108,5