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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
grojnak
New Member

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" to "office" or "office" to "home" had each employee. Of course, each change should be coherent in time. For example, for one employee:

dateLocation
25/09home
26/09office
27/09home
28/09home
29/09home

 

the count should be 2. How can I do that? I may also need to detail only the changes. Which is the best approach? A new column with M? A new table? I discard the measure, because of that need of the detailed info of only the changes.

 

Thanks,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @grojnak ,

 

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

My Sample:

vrzhoumsft_0-1695276559847.png

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.

vrzhoumsft_1-1695276579324.png

 

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.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @grojnak ,

 

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

My Sample:

vrzhoumsft_0-1695276559847.png

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.

vrzhoumsft_1-1695276579324.png

 

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.

 

lbendlin
Super User
Super User

Yes, this can easily be done in Power Query via grouping.  Read about GroupKind.Local

 

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.