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

DAX measure needed to calculate life of parts based on Installed dates

Not very new to DAX but not an expert in anyway. I have a dataset of part failures (over 2M rows) by system ID. As parts fail, those get replaced by either the same or a different (version of the) part. I need to pick up the failure time and survival time for parts using the Part number key. For failing parts, age is given in the original dataset. However, as I change the timeline slicer, a failed part may not have failed at that time. For example, if date is set to July-2020 the first part in the table below will actually be in a working state. In that case, I'll have to go back in the records and see when the system 101220 had tat PartA installed and calculate the days of survival (for unfailed parts). I need this measure that determines what parts have not failed on a given date (time slicer that will pick months or quarters) and for each given part, calculate the days of survival period (life) for those parts? 

 

Following is a sample of my dataset:

SystemIDComponent FailingComponent ReplacingDatePart Age (Days)
101220PartAPartA8/2/2020200
101220PartBPartC8/31/2020150
101220PartAPartD2/1/2021183
101330PartDPartD6/30/202190
101330PartAPartA9/21/2020218
101330PartAPartD2/2/2021134
101330PartCPartC9/2/2021343

 

Required result is in the following format and I am looking for a measure for Avg Life that provides me with the values given in that column. PartA on system 101330 was installed on Sep 21, 2021 and therefore has 404 days of age. That's the only 1 surviving PartA. In case of PartD it is average of two parts (installed on 2/1/2021 and 2/2/2021). 

 

Component IDInstalledFailedAvg AgeAvg Life
PartA24183.75404
PartB01150-
PartC21343241
PartD3190270

 

Thank you for your help in guiding me to get the Avg Life measure in DAX (I am using Excel PowerPivots and not Power BI) for this project

1 ACCEPTED SOLUTION

Hi @ali1234 ,

 

On top of the measure I have send add the following measure:

 

Days = 
VAR TempTable =
    CALCULATETABLE (
        SUMMARIZE (
            'Table',
            'Table'[Component Failing],
            'Table'[Component Replacing],
            'Table'[Date],
            'Table'[SystemID],
            "@DaysInstalled", DATEDIFF ( 'Table'[Date], TODAY (), DAY )
        ),
        'Table'[Component Replacing] IN VALUES ( Parts[Parts] )
    )
RETURN
    AVERAGEX ( TempTable, [@DaysInstalled] )

 

Check result in attach PBIX file:

MFelix_0-1635931816276.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

5 REPLIES 5
MFelix
Super User
Super User

Hi @ali1234 ,

 

For this you need to have a parts table in order to make the calculations because you have more than one column with the parts in this case I have created a table without relationship and made the following measures:

 

Failed = CALCULATE(COUNT('Table'[Component Failing]), 'Table'[Component Failing] in VALUES( PArts[Component]))

installed = calculate (COUNT('Table'[Component Replacing]),'Table'[Component Replacing] in VALUES(PArts[Component])) + 0

Average days = CALCULATE(AVERAGE('Table'[Part Age (Days)]),'Table'[Component Failing] in VALUES(PArts[Component]))

 

However the last column I'm not sure how you are calculating can you explain a little better how you are getting for example the 404 or the 241?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



V-pazhen-msft
Community Support
Community Support

@ali1234 


"PartA on system 101330 was installed on Sep 21, 2021 and therefore has 404 days of age"

 

I cannot figure out where is the 404 comes from in this sample table, can you explain the calculation please.

 

 

Best regards
Paul Zheng

 

Sorry for the confusion... 

PartA on system 101330 was installed on Sep21, 2020. I had a typo. See the first table that shows the install date. 440 days would be the time if the part still had not failed until end of October 2021 (in this case the part actually failed on 2/2/201, so it was a bad example. However, if you ignore that failure, then 440 comes from the installation date to end of the selected time period if a part has not failed).

 

The Avg Life calculation has to be done based on selected calendar time. So, based on the date of 10/30/2021 (if it was selected), Part C average age will be the average of 425 (for the part installed on 8/31/2020) and 58 (age of part installed on 9/2/2021). That'll give us ~242. 

 

Apologies for putting the table incorrectly in the original email. 

Hi @ali1234 ,

 

On top of the measure I have send add the following measure:

 

Days = 
VAR TempTable =
    CALCULATETABLE (
        SUMMARIZE (
            'Table',
            'Table'[Component Failing],
            'Table'[Component Replacing],
            'Table'[Date],
            'Table'[SystemID],
            "@DaysInstalled", DATEDIFF ( 'Table'[Date], TODAY (), DAY )
        ),
        'Table'[Component Replacing] IN VALUES ( Parts[Parts] )
    )
RETURN
    AVERAGEX ( TempTable, [@DaysInstalled] )

 

Check result in attach PBIX file:

MFelix_0-1635931816276.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



ali1234
Helper I
Helper I

@MFelix ... any thoughts on how to get around this?

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.