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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Duplicate Rows based on values

I'd like to duplicate rows when a column has the value "Weekly", for each week from the "Date" to present. 

 

EventRecurringDate
Event AWeekly22/09/2020
Event BNo14/08/2020
Event CNo15/03/2020

 

How can I use Power Query to add rows for "Weekly" for each week since the "Date", and have the Date reflect that?

Something like

 

Event AWeekly22/09/2020
Event AWeekly29/09/2020
Event AWeekly06/10/2020
Event AWeekly13/10/2020
Event AWeekly20/10/2020
Event BNo14/08/2020
Event CNo15/03/2020
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

@Anonymous  Add several steps to the previous post as below:

let
    Source = #table({"Event","Recurring","Date"},{{"Event A","Weekly","9/22/2020"},{"Event B","No","8/14/2020"},{"Event C","No","3/15/2020"}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Date", type date}}, "en-US"),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type with Locale", "Custom", each if [Recurring] = "Weekly" then List.Generate(()=>[Date], each _ <= Date.From(DateTime.FixedLocalNow()), each _ + #duration(7,0,0,0)) else null),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Conditional Column", "Custom"),
    #"Added Conditional Column1" = Table.AddColumn(#"Expanded Custom", "Custom.1", each if [Recurring] = "Weekly" then [Custom] else [Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column1",{"Date", "Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Date"}})
in
    #"Renamed Columns"

Result:

111101.jpg

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

@Anonymous  Add several steps to the previous post as below:

let
    Source = #table({"Event","Recurring","Date"},{{"Event A","Weekly","9/22/2020"},{"Event B","No","8/14/2020"},{"Event C","No","3/15/2020"}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Date", type date}}, "en-US"),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type with Locale", "Custom", each if [Recurring] = "Weekly" then List.Generate(()=>[Date], each _ <= Date.From(DateTime.FixedLocalNow()), each _ + #duration(7,0,0,0)) else null),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Conditional Column", "Custom"),
    #"Added Conditional Column1" = Table.AddColumn(#"Expanded Custom", "Custom.1", each if [Recurring] = "Weekly" then [Custom] else [Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column1",{"Date", "Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Date"}})
in
    #"Renamed Columns"

Result:

111101.jpg

lbendlin
Super User
Super User

 

let
    Source = #table({"Event","Recurring","Date"},{{"Event A","Weekly","9/22/2020"},{"Event B","No","8/14/2020"},{"Event C","No","3/15/2020"}}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Recurring] = "Weekly" then List.Generate(()=>[Date], each _ <= Date.From(DateTime.FixedLocalNow()), each _ + #duration(7,0,0,0)) else null),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Conditional Column", "Custom")
in
    #"Expanded Custom"

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors