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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
babyjb1979
Helper I
Helper I

Calculation for consecutive work days for employee

Hello everyone,

 

I've been tasked with creating a report that tracks consecutive workdays. Within the employee transaction table, there are two key columns: [Employee ID] and [Work Date]. I've already added a new column that's working well, except it's not applied correctly when employees are grouped together.



babyjb1979_0-1693951850159.png

In an attempt to refine the report further, I introduced another column. Unfortunately, this didn't yield the desired results.

babyjb1979_1-1693952635820.png

I'm in need of your assistance to make this report accurate and effective. Your help would be greatly appreciated!

 

 

1 ACCEPTED SOLUTION

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc2xDcAgDETRXVwjnTmDSWZB7L8GRarI177i/70tmLmsmQd6B8NO+yGnwqXwUfgKDFdY7wNemwNkwQlPgfxG5wI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee Number" = _t, #"Work Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee Number", Int64.Type}, {"Work Date", type date}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Consecutive", each if [Index]=0 then 1 else List.Accumulate({1..[Index]},1,(state,current)=> if #"Added Index"[Work Date]{current-1}=#"Added Index"[Work Date]{current}+#duration(-1,0,0,0) then state + 1 else 1))
in
    #"Added Custom"

View solution in original post

8 REPLIES 8
lbendlin
Super User
Super User

This can be done much simpler in Power Query.

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Please advise the solution by Power Query. I am in a hurry! Thank you a million!!!!

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc2xDcAgDETRXVwjnTmDSWZB7L8GRarI177i/70tmLmsmQd6B8NO+yGnwqXwUfgKDFdY7wNemwNkwQlPgfxG5wI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee Number" = _t, #"Work Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee Number", Int64.Type}, {"Work Date", type date}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Consecutive", each if [Index]=0 then 1 else List.Accumulate({1..[Index]},1,(state,current)=> if #"Added Index"[Work Date]{current-1}=#"Added Index"[Work Date]{current}+#duration(-1,0,0,0) then state + 1 else 1))
in
    #"Added Custom"

But once I add the new column in Power Query, when close and apply, it is loading forever. There are 1.3 million rows. It will load many days. How can I optimize the query? 

Thank you!

babyjb1979_0-1694118982912.png

 

Please provide sample data that fully covers your issue.

 

Please revise employee number to different numbers.  Thank you!

Employee NumberWork Date
3266703/11/23
3266703/25/23
3266703/27/23
3266703/28/23
3266703/29/23
3266703/30/23
3266703/31/23
3266704/08/23
3266704/22/23
3266705/06/23
3266705/20/23

Please revise employee number to different numbers.  Thank you!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.