Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Splitting rows containing a date interval into as many rows as the nr of weeks of the given interval

Hi community, I am a biginner with Power Query and cannot resolve this problem: This is my starting point, where a single row contains: start date, end date, total workload, number of weeks,  Ta...
  • ronrsnfld's avatar
    3 years ago

    You can Add a Custom Column with the formula:

     

    {0..[Number of Weeks]}

     

     

    Then merely expand that List to new rows, and delete the added column

    let
    
    //Change next line to reflect actual data source
        Source = Excel.CurrentWorkbook(){[Name="Table13"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{
            {"Task", type text}, {"Start Date", type date}, {"End Date", type date}, {"Department", type text}, 
            {"Employee", type text}, {"WorkLoad", Int64.Type}, {"Number of Weeks", Int64.Type}, 
            {"Solar Days", Int64.Type}, {"Weekly Mean Workload", Int64.Type}}),
    
    //Add custom column with list of {0..number of weeks}
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {0..[Number of Weeks]}, type list),
    
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Custom"})
    in
        #"Removed Columns"