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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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.LearnAndPractise(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.LearnAndPractise(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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.