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

Get Fabric certified for FREE! Don't miss your chance! Learn more

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.


Follow on LinkedIn
@ 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!:
DAX For Humans

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
Community Champion
Community Champion

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


Follow on LinkedIn
@ 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!:
DAX For Humans

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.


Follow on LinkedIn
@ 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!:
DAX For Humans

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. 

 



Follow on LinkedIn
@ 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!:
DAX For Humans

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



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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


Follow on LinkedIn
@ 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!:
DAX For Humans

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
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.