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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
KvO88
Frequent Visitor

Calculate Age of spare part between failures

I want to know the lifetime of a spare part based on dates in different rows. Example: the age of the spare part after first replacement will be "date of replacement - installation date". When that same part is replaced again on the same system, I want to calculate the age since the replacement "date of 2nd replacement-date of 1st replacement" and so on. 

 

See below a simplified example of a table containing the replacements of a single spare part:

 

Unique System IDSpare Part IDSystem Install DatePart Replacement DateAge of part?
15330 01801-Jan-202301-Feb-2023 
25330 01823-Feb-202305-Apr-2023 
35330 01804-Mar-202308-Aug-2023 
45330 01812-May-20233-Sep-2023 
15330 01801-Jan-202319-Nov-2023 
25330 01823-Feb-202318-Nov-2023 
55330 01817-Jul-202323-Nov-2023 
15330 01801-Jan-202301-Jan-2024 
65330 01805-Sep-202318-Jan-2024 
35330 01804-Mar-20235-Oct-2023 

 

1 ACCEPTED SOLUTION
v-yifanw-msft
Community Support
Community Support

Hi @KvO88 ,
I believe that @Greg_Deckler 's answer will be of great help to you and in the meantime I have created some data for you to help you and I hope that the combination of our answers will help you to solve your problem. You can follow the steps below:

1.Add a new column.

Age of Part = 
VAR _ID = 'Table'[Spare Part ID]
VAR _Date = 'Table'[Part Replacement Date]
RETURN
DATEDIFF(
    CALCULATE(
        MAX('Table'[Part Replacement Date]),
        FILTER(
            'Table',
            'Table'[Spare Part ID] = _ID
            && 'Table'[Part Replacement Date] < _Date
        )
    ),
    _Date,
    DAY
)

Final output:

vyifanwmsft_0-1711090640776.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

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

4 REPLIES 4
v-yifanw-msft
Community Support
Community Support

Hi @KvO88 ,
I believe that @Greg_Deckler 's answer will be of great help to you and in the meantime I have created some data for you to help you and I hope that the combination of our answers will help you to solve your problem. You can follow the steps below:

1.Add a new column.

Age of Part = 
VAR _ID = 'Table'[Spare Part ID]
VAR _Date = 'Table'[Part Replacement Date]
RETURN
DATEDIFF(
    CALCULATE(
        MAX('Table'[Part Replacement Date]),
        FILTER(
            'Table',
            'Table'[Spare Part ID] = _ID
            && 'Table'[Part Replacement Date] < _Date
        )
    ),
    _Date,
    DAY
)

Final output:

vyifanwmsft_0-1711090640776.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yifanw-msft ,

This still does not calculate the age of the part until the first time it was replaced, so the datediff install date, first time replaced. Do you know how I can integrate that in this approach?

Greg_Deckler
Super User
Super User

@KvO88 See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
 ( __Current - __Previous ) * 1.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler,

Thank you, I did find your article very helpful. There is one thing that I am struggeling with, what I cannot get right is that the first meantime between failure should be the date a first time a repair was needed minus (-) the installation date. That is currently not in the "Uptime" calculation if I am correct.  

Can you help me a little further with that?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.