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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Rygar
Helper II
Helper II

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

 

Example_From_To_Date.png

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

  • 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))

ronrsnfld_0-1637454078606.png

 

  • 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"

 

 

ronrsnfld_1-1637454267265.png

 

 

 

View solution in original post

2 REPLIES 2
ronrsnfld
Super User
Super User

  • 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))

ronrsnfld_0-1637454078606.png

 

  • 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"

 

 

ronrsnfld_1-1637454267265.png

 

 

 

Really cool and so easy! Thank you very much!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors