cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arthurr Frequent Visitor
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

Accepted Solutions
v-yulgu-msft Super Contributor
Super Contributor

Re: Having trouble in subtracting months

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 Super Contributor
Super Contributor

Re: Having trouble in subtracting months

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.
arthurr Frequent Visitor
Frequent Visitor

Re: Having trouble in subtracting months

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 

v-yulgu-msft Super Contributor
Super Contributor

Re: Having trouble in subtracting months

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

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 174 members 1,966 guests
Please welcome our newest community members: