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
jhowe
Regular Visitor

Loop through table to turn one row into multiple rows

Hello,

 

I am trying to figure out a method for turning one row of data for a particular time frame into several rows for that same duration of time. The image shows an example of what I want to do. The first row in the green table should be split into the first 2 rows of the blue table and the second row of the green table should be split into the last 3 rows of the blue table. I have tried doing this with the List.Dates function and the Table.SelectRows function but the list dates function cannot convert my table into type date. I thought a loop might allow me to go row by row in my table and pull out the Start and End dates. Any assistance or ideas you can provide are welcomed. Thank you!

 Loop.PNG

loop2.PNG

1 ACCEPTED SOLUTION
jahida
Impactful Individual
Impactful Individual

Before trying to do anything else, you should make sure the column is of type date (you can do this in the wizard under transform). Then, you can use something like this M code to get the rest of it done:

 

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Days", each Duration.Days([End] - [Start]) + 1),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each List.Dates([Start], [Days], #duration(1, 0, 0, 0))),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom")

 

View solution in original post

1 REPLY 1
jahida
Impactful Individual
Impactful Individual

Before trying to do anything else, you should make sure the column is of type date (you can do this in the wizard under transform). Then, you can use something like this M code to get the rest of it done:

 

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Days", each Duration.Days([End] - [Start]) + 1),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each List.Dates([Start], [Days], #duration(1, 0, 0, 0))),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "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.