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
rbartlejr
Helper III
Helper III

Problems with MTBF calculations

I've been trying to emulate the MTBF calculations in this blog post: https://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339.... I'm having problems with the Dax formulas in it. For example, the author shows:

Uptime =

VAR next = MINX(FILTER(Repairs,

                       Repairs[MachineName]=EARLIER(Repairs[MachineName]) &&

                       Repairs[RepairStarted]>EARLIER(Repairs[RepairStarted]) &&

                       Repairs[RepairType]<>"PM"

               ),Repairs[RepairStarted])

RETURN IF([RepairType]="PM", 0,IF(ISBLANK(next),

               DATEDIFF([RepairCompleted],NOW(),SECOND),

               DATEDIFF([RepairCompleted],next,SECOND)

           )

       )

 

I modified it to my data and get this:

Uptime =

VAR next = MINX(FILTER(Repairs,

          Repairs[Asset #]=EARLIER(Repairs[Asset #]) &&

          Repairs[DateIn]>EARLIER(Repairs[DateIn]) &&

          Repairs[comments]<>"Return to bin"

          ),Repairs[DateIn].[Day])

RETURN IF(Repairs[comments]="Return to bin", 0,IF(ISBLANK(next),

          DATEDIFF([DateOut],NOW(),DAY),

           DATEDIFF([DateOut],next,Day)

     )
)

 

I get this error: The syntax for ',' is incorrect. (DAX(VAR next = MINX(FILTER(Repairs, Repairs[Asset #]=EARLIER(Repairs[Asset #]) && Repairs[DateIn]>EARLIER(Repairs[DateIn]) && Repairs[comments]<>"Return to bin" ),Repairs[DateIn].[Day])RETURN IF(Repairs[comments="Return to bin", 0,IF(ISBLANK(next), DATEDIFF([DateOut],NOW(),DAY), DATEDIFF([DateOut],next,Day) ) ))).

 

I also get red  underlines under all of the columns next to EARLIER and DATEDIFF. Anyone have any ideas?

 

2 ACCEPTED SOLUTIONS

Looks like you are missing a comma or semi-colon after the VAR next line.

@ 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...

View solution in original post

Yes! I was missing the comma. BTW I just bought your book. Thanks for your help!

View solution in original post

9 REPLIES 9
Greg_Deckler
Super User
Super User

Sounds like you need to change the commas to semi-colons ( ; ). Regional language settings.

@ 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...

@Greg_Deckler Ok, I tried that and get this error: EARLIER/EARLIEST refers to an earlier row context which doesn't exist. I looked in the data and there are more than one asset #s in several rows.

And is this a column you are creating? It should be a column and not a measure if I remember correctly.

@ 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...

It shows in the blog article as a measure; the data is set into columns for date, asset #, etc. I can calculate a column for the repair time (already done) since the Repair Hours measure didn't work either.

Here is the original PBIX attached below if it helps.

 

I checked and Uptime is a calculated column. Also, read through the comments as I think there were some bugs/issues that were hammered out that I eventually included in my book DAX Cookbook. The book now has the best version of this. I can take a look at that and see if it helps. Let me know. 

 


@ 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...

Spoiler
I appreciate the PBIX file. You were right but it still doesn't work. Here is a screenshot:

MTBF.jpg

Not to be that guy, but the code in the PBIX file I sent certainly works.

 

image.png


@ 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...

Looks like you are missing a comma or semi-colon after the VAR next line.

@ 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...

Yes! I was missing the comma. BTW I just bought your book. Thanks for your help!

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.