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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
someguy
Frequent Visitor

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

@someguy  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

@someguy  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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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