Forum Discussion

Rygar's avatar
Rygar
Helper II
4 years ago
Solved

Transform Table with FROM TO Date into multiple line/dates Table

Dear Community,

 

can anyone help me, with the transformation below?

I Think it should be possible without programming a loop...

Here is an Example file

 

Many thanks an regards,

Michael

 

 

    • This can all be done from the GUI
    • Create  a custom column with the date lists and give it a name of "Date"
      • List.Dates([From],Duration.Days([To]-[From])+1,#duration(1,0,0,0))

     

    • Delete the From/To Columns
    • Move the new Date column to the proper location
    • Expand the Date column into Rows (click on the two headed arrow at the top of the column and you will see that as an option)

     

    M Code from Advanced Editor

     

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{
            {"ProductFamily", type text}, {"From", type date}, {"To", type date}, {"ID", type text}}),
        
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", 
            each List.Dates([From],Duration.Days([To]-[From])+1,#duration(1,0,0,0))),
        
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"From", "To"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ProductFamily", "Date", "ID"}),
       #"Expanded Date" = Table.ExpandListColumn(#"Reordered Columns", "Date"),
       #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}})
    in
        #"Changed Type1"

     

     

     

     

     

2 Replies

    • This can all be done from the GUI
    • Create  a custom column with the date lists and give it a name of "Date"
      • List.Dates([From],Duration.Days([To]-[From])+1,#duration(1,0,0,0))

     

    • Delete the From/To Columns
    • Move the new Date column to the proper location
    • Expand the Date column into Rows (click on the two headed arrow at the top of the column and you will see that as an option)

     

    M Code from Advanced Editor

     

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{
            {"ProductFamily", type text}, {"From", type date}, {"To", type date}, {"ID", type text}}),
        
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", 
            each List.Dates([From],Duration.Days([To]-[From])+1,#duration(1,0,0,0))),
        
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"From", "To"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ProductFamily", "Date", "ID"}),
       #"Expanded Date" = Table.ExpandListColumn(#"Reordered Columns", "Date"),
       #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}})
    in
        #"Changed Type1"

     

     

     

     

     

    • Rygar's avatar
      Rygar
      Helper II

      Really cool and so easy! Thank you very much!