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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
arthurr
Frequent Visitor

Having trouble in subtracting months

Hi,

 

I am trying to calculate the mean time between failures for our Service department. For a given month the formula works fine. The issue begins when I choose range of more than one month. in the slicer. I need an expression that counts the number of months within the range (assuming that it can also be across different years).

 

MTBF (Days) = (LASTNONBLANK('Cases'[Closed Date (A)].[Day],1)-FIRSTNONBLANK('Cases'[Closed Date (A)].[Day],1)+1)/COUNT('Cases'[Case ID])*(MONTH(LASTNONBLANK('Cases'[Closed Date (A)].[Date],1)-MONTH(FIRSTNONBLANK('Cases'[Closed Date (A)].[Date],1)+1)))

 

 

1 ACCEPTED SOLUTION

Hi @arthurr,

 

# of days =
DATEDIFF (
    MIN ( 'Cases'[Closed Date (A)] ),
    MAX ( 'Cases'[Closed Date (A)] ),
    DAY
)

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @arthurr,

 

It looks like you placed wrong parentheses in above formula. Please modify it to:

MTBF (Days) =
 (
    LASTNONBLANK ( 'Cases'[Closed Date (A)].[Day], 1 )
        - FIRSTNONBLANK ( 'Cases'[Closed Date (A)].[Day], 1 )
        + 1
)
    / COUNT ( 'Cases'[Case ID] )
    * (
        MONTH ( LASTNONBLANK ( 'Cases'[Closed Date (A)].[Date], 1 ) )
            - MONTH ( FIRSTNONBLANK ( 'Cases'[Closed Date (A)].[Date], 1 ) )
            + 1
    )

Besides, to calculate time intervals between two date/time values, you can use DATEDIFFfunction.

 

MTBF (Days) =
DATEDIFF (
    MIN ( 'Cases'[Closed Date (A)] ),
    MAX ( 'Cases'[Closed Date (A)] ),
    DAY
)
    / COUNT ( 'Cases'[Case ID] )
    * DATEDIFF (
        MIN ( 'Cases'[Closed Date (A)] ),
        MAX ( 'Cases'[Closed Date (A)] ),
        MONTH
    )

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

Thank you, but I have now a better understanding of my issue. I have a date slicer for 

'Cases'[Closed Date (A)]

and I would like to calculate the # of days between the 2 selections in the slicer. Issue is, that in my dataset there are no neccesseraly values in all dates. Is there a way I can use the dta points from the slicer?

 

Thanks 

Hi @arthurr,

 

# of days =
DATEDIFF (
    MIN ( 'Cases'[Closed Date (A)] ),
    MAX ( 'Cases'[Closed Date (A)] ),
    DAY
)

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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