Forum Discussion
Create a new table depending on range
Hi there,
I want to create a new table depending on range, I got the following data;
but I want to see it the following way;
Thanks in advanced.
10 Replies
- mahoneypatMicrosoft 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
- Ashish_MathurSuper User
Hi,
This M code will work
={Number.From([StartDate])..Number.From([EndDate])}
Then expand this new column.
Hope this helps.
- AnonymousNot applicable
The solution send me the following error
- Ashish_MathurSuper User
You are missing the curly brackets at the beginning and end.