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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
SHER101
Frequent Visitor

NEW to PBI

How do I edit this to not include weekends

 

= Table.AddColumn(#"Added Conditional Column", "SiteWalk CycleTime", each Duration.Days ([site_visit_acd] - [cpin_received_acd]))

1 ACCEPTED SOLUTION
v-junyant-msft
Community Support
Community Support

Hi @SHER101 ,

Please try this:

let 
   StartDate = [site_visit_acd],
   EndDate = [cpin_received_acd],
   TotalDays = Duration.Days(EndDate - StartDate) + 1,
   RemoveWeekends = List.Numbers(0, TotalDays, 1),
   DaysList = List.Transform(RemoveWeekends, each Date.AddDays(StartDate, _)),
   WeekDays = List.Select(DaysList, each Date.DayOfWeek(_, Day.Monday) < 5)
in 
   List.Count(WeekDays)

vjunyantmsft_0-1726191163008.png

Here is the whole M code in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtEz1DNU0oExzZVidaDiRghxIz0zhLgxQtxYzxQhboIQB0Kl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [site_visit_acd = _t, cpin_received_acd = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"site_visit_acd", type date}, {"cpin_received_acd", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "SiteWalk CycleTime", each let 
   StartDate = [site_visit_acd],
   EndDate = [cpin_received_acd],
   TotalDays = Duration.Days(EndDate - StartDate) + 1,
   RemoveWeekends = List.Numbers(0, TotalDays, 1),
   DaysList = List.Transform(RemoveWeekends, each Date.AddDays(StartDate, _)),
   WeekDays = List.Select(DaysList, each Date.DayOfWeek(_, Day.Monday) < 5)
in 
   List.Count(WeekDays))
in
    #"Added Custom"


Best Regards,
Dino Tao
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
v-junyant-msft
Community Support
Community Support

Hi @SHER101 ,

Please try this:

let 
   StartDate = [site_visit_acd],
   EndDate = [cpin_received_acd],
   TotalDays = Duration.Days(EndDate - StartDate) + 1,
   RemoveWeekends = List.Numbers(0, TotalDays, 1),
   DaysList = List.Transform(RemoveWeekends, each Date.AddDays(StartDate, _)),
   WeekDays = List.Select(DaysList, each Date.DayOfWeek(_, Day.Monday) < 5)
in 
   List.Count(WeekDays)

vjunyantmsft_0-1726191163008.png

Here is the whole M code in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtEz1DNU0oExzZVidaDiRghxIz0zhLgxQtxYzxQhboIQB0Kl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [site_visit_acd = _t, cpin_received_acd = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"site_visit_acd", type date}, {"cpin_received_acd", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "SiteWalk CycleTime", each let 
   StartDate = [site_visit_acd],
   EndDate = [cpin_received_acd],
   TotalDays = Duration.Days(EndDate - StartDate) + 1,
   RemoveWeekends = List.Numbers(0, TotalDays, 1),
   DaysList = List.Transform(RemoveWeekends, each Date.AddDays(StartDate, _)),
   WeekDays = List.Select(DaysList, each Date.DayOfWeek(_, Day.Monday) < 5)
in 
   List.Count(WeekDays))
in
    #"Added Custom"


Best Regards,
Dino Tao
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

What is your definition of weekend?

 

What is your expected result when [site_visit_acd] is the same as [cpi_received_acd] ?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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