Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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]))
Solved! Go to Solution.
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)
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.
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)
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.
What is your definition of weekend?
What is your expected result when [site_visit_acd] is the same as [cpi_received_acd] ?
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |