Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Create a new table depending on range

Hi there,

I want to create a new table depending on range, I got the following data;

Range.PNG

but I want to see it the following way;

range2.PNG

Thanks in advanced.

10 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    To do this, you can create a new columns with a List of the dates between start and end date, and then expand that list to new rows.  See example M code below (note I started in a different date locale, so you may need to add a step with my example data to change to your locale).  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJQ0gEyjeFsIBGrE61khJA10jeygLFNgLKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t, EndDate = _t, Rate = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"StartDate", type date}, {"EndDate", type date}, {"Rate", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Dates", each List.Dates([StartDate], Duration.TotalDays([EndDate]-[StartDate])+1, #duration(1,0,0,0))),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Dates", "Rate"}),
        #"Expanded Dates" = Table.ExpandListColumn(#"Removed Other Columns", "Dates")
    in
        #"Expanded Dates"

     

    Regards,

    Pat

     

  • Hi,

    This M code will work

    ={Number.From([StartDate])..Number.From([EndDate])}

    Then expand this new column.

    Hope this helps.

    • Anonymous's avatar
      Anonymous
      Not applicable

      The solution send me the following error

      Range3.PNG