Forum Discussion

KUMAR_AK's avatar
KUMAR_AK
Icon for Microsoft Employee rankMicrosoft Employee
4 years ago
Solved

Minus Breaktime Between Start and End Time

Hi Everyone,

I was hoping someone could help me with a part of the formula to get me to my end goal.
I have the below dataset

 

 

StartTimeEndTimeIDNameBreakDetails
10/13/2021 6:55:00 AMnullA-125698LoginNo Breaktime
10/13/2021 7:00:00 AM10/13/2021 7:30:00 AMB-125698 IssuesBreak
10/13/2021 9:00:00 AMnullC-125698StartNo Breaktime
10/13/2021 10:00:00 AM10/13/2021 11:00:00 AMD-125698Issuewaiting
10/13/2021 11:30:00 AM10/13/2021 11:45:00 AME-125698 IssuesBreaktime
10/13/2021 1:00:00 PMnullF-125698XOOJwaiting time
10/13/2021 1:10:00 PMnullG-125698EndNo Breaktime
10/13/2021 1:45:00 PM10/13/2021 2:40:00 PMH-125698NextNo Breaktime
10/13/2021 3:00:00 PMnullC-125698Startwaiting time
10/13/2021 3:15:00 PM10/13/2021 3:30:00 PMI-125698RITNo Breaktime
10/13/2021 4:00:00 PM10/13/2021 16:30F-125698InjectBreaktime
10/13/2021 5:00:00 PM10/13/2021 5:30:00 PMK-125698RIHwaiting time
10/13/2021 6:00:00 PMnullC-125698Millwaiting time
10/13/2021 6:30:00 PM10/13/2021 7:00:00 PMM-125698Tagwaiting time
10/13/2021 7:30:00 PMnullF-125698EndNo Breaktime
10/13/2021 8:00:00 PMnullS-125698DownNo Breaktime
10/13/2021 21:00nullt-125698Job TicketNo Breaktime



2. for breaktime we will have end date for that 

IF there is any break time in between start and end i want to minus that time from start and end time.

Expected Output 

FROM ABOVE TABLE IM LOOKING FOR THE BELOW DATE CALUCATIONS

 

 

 

2.break DURING TIME --- 

OUT OF 250 MINUTES MINUS (10/13/2021 11:30:00 AM - 10/13/2021 11:45:00 AM) = 15 MINUTE

 

OUT OF 300 MINUTES (3rd OPEN START TIME AND CLOSE TIME ) 90 MINUS (10/13/2021 4:30:00 PM - 10/13/2021 4:30:00 PM) = 30 MINUTES

BreakTIME = 45 MINUTES



Thanks 
Kumar

  • Hi, KUMAR_AK 

     

    I used other logic to implement it before, so it will be relatively simple

    If it must be this logic, Dax is not easy to express. Sometimes the logic of the language is converted into dax, which is not as simple as it seems, it is very complicated.

    I hope you provide the sample won't change...😅

    Try:

    Measure =
    IF (
        HASONEVALUE ( 'Table'[starttime] ),
        SUMX (
            ADDCOLUMNS (
                SUMMARIZE (
                    FILTER ( ALL ( 'Table' ), [name] = "Open" ),
                    [starttime],
                    "enddate",
                        MINX (
                            FILTER (
                                ALL ( 'Table' ),
                                [name] = "Close"
                                    && [starttime] > EARLIER ( 'Table'[starttime] )
                            ),
                            [starttime]
                        )
                ),
                "breaktime",
                    SUMX (
                        FILTER (
                            ALL ( 'Table' ),
                            [starttime] > EARLIER ( 'Table'[starttime] )
                                && [starttime] < EARLIER ( [enddate] )
                                && [breakdetails] = "Breaktime"
                                && [starttime] = SELECTEDVALUE ( 'Table'[starttime] )
                        ),
                        DATEDIFF ( [starttime], [_Endtime], MINUTE )
                    )
            ),
            [breaktime]
        ),
        SUMX (
            ADDCOLUMNS (
                SUMMARIZE (
                    FILTER ( ALL ( 'Table' ), [name] = "Open" ),
                    [starttime],
                    "enddate",
                        MINX (
                            FILTER (
                                ALL ( 'Table' ),
                                [name] = "Close"
                                    && [starttime] > EARLIER ( 'Table'[starttime] )
                            ),
                            [starttime]
                        )
                ),
                "breaktime",
                    SUMX (
                        FILTER (
                            ALL ( 'Table' ),
                            [starttime] > EARLIER ( 'Table'[starttime] )
                                && [starttime] < EARLIER ( [enddate] )
                                && [breakdetails] = "Breaktime"
                        ),
                        DATEDIFF ( [starttime], [_Endtime], MINUTE )
                    )
            ),
            [breaktime]
        )
    )
    

     

     

    Did I answer your question ? Please mark my reply as solution. Thank you very much.
    If not, please feel free to ask me.


    Best Regards,
    Community Support Team _ Janey

14 Replies

  • Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. 

    • KUMAR_AK's avatar
      KUMAR_AK
      Icon for Microsoft Employee rankMicrosoft Employee

      Hello 
      Added sample in table format and expeceted output in description

      Thanks
      Kumar

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        Is there any meaning behind the ID field or is it all for the same person/process?

  • KUMAR_AK's avatar
    KUMAR_AK
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi ID is for identifying start and end I'd 's and those start if and end if are unique to identify start or end remaining or random 

  • KUMAR_AK's avatar
    KUMAR_AK
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi ID is for identifying start and end I'd 's and those start if and end if are unique to identify start or end remaining or random 

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Icon for Community Support rankCommunity Support

    Hi, KUMAR_AK 

     

    According to your description, I think you can create two measures to get your desired result.

    Like this:

    TOTAL POTENTIAL TIME = 
    SUMX (
        SUMMARIZE (
            'Table',
            [startdate],
            [enddate],
            [name],
            "a",
                VAR startdate =
                    CALCULATE ( MAX ( 'Table'[startdate] ), 'Table'[name] = "start" )
                VAR enddate =
                    IF (
                        SELECTEDVALUE ( 'Table'[name] ) = "start",
                        MINX (
                            FILTER (
                                ALL ( 'Table' ),
                                [name] = "end"
                                    && [startdate] > SELECTEDVALUE ( 'Table'[startdate] )
                            ),
                            [startdate]
                        )
                    )
                RETURN
                    DATEDIFF ( SELECTEDVALUE ( 'Table'[startdate] ), enddate, MINUTE )
        ),
        [a]
    )
    
    
    NPT DURING TOTAL POTENTIAL TIME =
    SUMX (
        SUMMARIZE (
            'Table',
            [startdate],
            [enddate],
            [name],
            "a",
                VAR minstart =
                    CALCULATE (
                        MIN ( 'Table'[startdate] ),
                        FILTER ( ALL ( 'Table' ), 'Table'[name] = "start" )
                    )
                VAR maxend =
                    CALCULATE (
                        MAX ( 'Table'[startdate] ),
                        FILTER ( ALL ( 'Table' ), 'Table'[name] = "end" )
                    )
                VAR maxdate =
                    MAXX (
                        FILTER (
                            ALL ( 'Table' ),
                            [name] <> "breaktime"
                                && [startdate] < SELECTEDVALUE ( 'Table'[startdate] )
                        ),
                        [startdate]
                    )
                VAR statename =
                    MAXX ( FILTER ( ALL ( 'Table' ), [startdate] = maxdate ), [name] )
                RETURN
                    IF (
                        SELECTEDVALUE ( 'Table'[name] ) = "breaktime"
                            && SELECTEDVALUE ( 'Table'[startdate] ) > minstart
                            && SELECTEDVALUE ( 'Table'[startdate] ) < maxend
                            && statename = "start",
                        DATEDIFF (
                            SELECTEDVALUE ( 'Table'[startdate] ),
                            SELECTEDVALUE ( 'Table'[enddate] ),
                            MINUTE
                        )
                    )
        ),
        [a]
    )
    
    

    Below is my sample. Hope it helps.

     

    Did I answer your question ? Please mark my reply as solution. Thank you very much.
    If not, please feel free to ask me.


    Best Regards,
    Community Support Team _ Janey

    • KUMAR_AK's avatar
      KUMAR_AK
      Icon for Microsoft Employee rankMicrosoft Employee

      Hi v-janeyg-msft 
      Thanks for the info, it works , just trying to implement the same if Breaktime is in Seperate column like break details 
      Calculation is same just encountering some error in  below piece of codefor npt during potentioal time 

      VAR maxdate =
      MAXX (
      FILTER (
      ALL ( 'Table' ),
      [name] <> "breaktime"
      && [startdate] < SELECTEDVALUE ( 'Table'[startdate] )
      ),
      [startdate]
      )
      VAR statename =
      MAXX ( FILTER ( ALL ( 'Table' ), [startdate] = maxdate ), [name])



      If you can elp me in that thats works Please 

      Thanks 
      Kumar

      • v-janeyg-msft's avatar
        v-janeyg-msft
        Icon for Community Support rankCommunity Support

        Hi, KUMAR_AK 

         

        Real breakdetails is better to write logic. I thought about the previous one for a long while.😅

        You can try:

         

        Measure = 
        SUMX (
            SUMMARIZE (
                'Table',
                [StartTime],
                [EndTime],
                [Name],
                "a",
                        IF (
                            SELECTEDVALUE ( 'Table'[BreakDetails] ) = "Breaktime",
                
                            DATEDIFF (
                                SELECTEDVALUE ( 'Table'[StartTime] ),
                                SELECTEDVALUE ( 'Table'[EndTime] ),
                                MINUTE
                            ),
                            0
                        )
            ),
            [a]
        )
        
        

         

        Best Regards,
        Community Support Team _ Janey