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
maghura
New Member

Generate dates from weekdays

Hi,

 

I want to generate dates corresponding to a list of weekdays within a date range. 

 

Here is my table:

 

ID  Time      Start Date    End Date     Recurrence
10 09:10:00 29/08/2023 08/09/2023 "Monday","Wednesday","Friday"
11 09:00:00 29/08/2023 29/10/2023 "Monday","Thursday","Friday"
12 10:00:00 23/08/2023 01/11/2023 "Monday","Tuesday","Wednesday","Thursday","Friday"

 

Here is an example for ID 10 of the output I would like to have:

 

ID  Time      Start date    End date     Recurrence date
10 09:10:00 29/08/2023 08/09/2023 30/08/2023
10 09:10:00 29/08/2023 08/09/2023 01/09/2023
10 09:10:00 29/08/2023 08/09/2023 04/09/2023
10 09:10:00 29/08/2023 08/09/2023 06/09/2023
10 09:10:00 29/08/2023 08/09/2023 08/09/2023

 

Thanks

1 ACCEPTED SOLUTION
ThxAlot
Super User
Super User

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lGytDI0sDIAsYws9Q0s9I0MjIyBHCDLwBLGiVHyzc9LSayMUdKJUQpPTclLLYbx3IoywUylWB2ggYZgAw2wGQjkGBpgNTAko7QIh3lGQLVg50ENNEZ2oaG+oSF2A0sR7kN1LQ6rYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID " = _t, #"Time " = _t, #"Start Date" = _t, #"End Date" = _t, Recurrence = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID ", Int64.Type}, {"Time ", type time}, {"Start Date", type date}, {"End Date", type date}, {"Recurrence", type text}}, "fr"),

    #"Recurrence Dates" = Table.ReplaceValue(
        #"Changed Type",
        each [Recurrence],
        each let
            span = List.Dates([Start Date], Duration.TotalDays([End Date]-[Start Date])+1, #duration(1,0,0,0)),
            rec_dt = List.Select(span, (dt) => Text.Contains([Recurrence], Date.DayOfWeekName(dt, "en-US")))
        in rec_dt,
        Replacer.ReplaceValue,
        {"Recurrence"}
    ),
    #"Expanded Recurrence" = Table.ExpandListColumn(#"Recurrence Dates", "Recurrence")
in
    #"Expanded Recurrence"

 

ThxAlot_0-1692705987659.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lGytDI0sDIAsYws9Q0s9I0MjIyBHCDLwBLGiVHyzc9LSayMUdKJUQpPTclLLYbx3IoywUylWB2ggYZgAw2wGQjkGBpgNTAko7QIh3lGQLVg50ENNEZ2oaG+oSF2A0sR7kN1LQ6rYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID " = _t, #"Time " = _t, #"Start Date" = _t, #"End Date" = _t, Recurrence = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID ", Int64.Type}, {"Time ", type time}, {"Start Date", type date}, {"End Date", type date}, {"Recurrence", type text}}, "fr"),

    #"Recurrence Dates" = Table.ReplaceValue(
        #"Changed Type",
        each [Recurrence],
        each let
            span = List.Dates([Start Date], Duration.TotalDays([End Date]-[Start Date])+1, #duration(1,0,0,0)),
            rec_dt = List.Select(span, (dt) => Text.Contains([Recurrence], Date.DayOfWeekName(dt, "en-US")))
        in rec_dt,
        Replacer.ReplaceValue,
        {"Recurrence"}
    ),
    #"Expanded Recurrence" = Table.ExpandListColumn(#"Recurrence Dates", "Recurrence")
in
    #"Expanded Recurrence"

 

ThxAlot_0-1692705987659.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Vijay_A_Verma
Super User
Super User

See the sample code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lGytDI0sDIAsYwMjIx1DSx0jSzhHEsgH8iJUfLNz0tJrNSJUQpPTclLLQayY5SAPLeiTDBTKVYHaJwh2DgDnMYZGkA4SMaFZJQW4TDNCKgS7DQ044zhxhnqGhiiGVeKcBuqS3FYFAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Time = _t, #"Start Date" = _t, #"End Date" = _t, Recurrence = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Time", type time}, {"Start Date", type date}, {"End Date", type date}, {"Recurrence", type text}}),
    #"Added Custom" = Table.RemoveColumns(Table.AddColumn(#"Changed Type", "Recurrence Date", each List.Select(List.Dates([Start Date], Duration.Days([End Date] - [Start Date]) + 1, #duration(1, 0, 0, 0)), (x)=> Text.Contains([Recurrence], Date.DayOfWeekName(x)))), {"Recurrence"}),
    #"Expanded Custom" = Table.TransformColumns(Table.ExpandListColumn(#"Added Custom", "Recurrence Date"), {"Recurrence Date", Date.From})
in
    #"Expanded Custom"

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.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.