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     StartTime EndTime ID Name BreakDetails 10/13/202...
  • v-janeyg-msft's avatar
    v-janeyg-msft
    4 years ago

    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