Forum Discussion

grojnak's avatar
grojnak
New Member
2 years ago
Solved

Count changes in a field (with date)

Hello.   I have a table with these fields: - employee: ID number of the worker - location: "home" or "office" - date: each day the employee worked   I need to count how many changes from "home...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi grojnak ,

     

    I suggest you to try code as below to create a measure.

    My Sample:

    Count Location Change For Employee =
    VAR _SUMMARIZE =
        SUMMARIZE (
            ADDCOLUMNS (
                'Table',
                "CheckPoint",
                    CALCULATE (
                        MIN ( 'Table'[date] ),
                        FILTER (
                            ALLEXCEPT ( 'Table', 'Table'[Employee ID] ),
                            'Table'[date] > EARLIER ( [date] )
                                && 'Table'[Location] <> EARLIER ( [Location] )
                        )
                    )
            ),
            [Employee ID],
            [CheckPoint]
        )
    RETURN
        COUNTX ( _SUMMARIZE, [CheckPoint] )

    Result is as below.

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.