Forum Discussion
jludwick
4 years agoFrequent Visitor
How do I create a timeframe table based off existing date table?
I have a date table that includes index columns for current day, current week, current month, etc. Here's how my date table looks: [Date] Date ID Current Day Index Current Week Index Current ...
- 4 years ago
Hi jludwick ,
You simply need to unpivot all columns except the date ID column, and then filter out values in column value that are <> 1.
Here is the sample M-code. you can copy and paste this into a blank query and see all the steps in detail.let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjIwMzRR0lEyAGJDMI7VgUuY4pIwgwuCJWIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date ID" = _t, #"Current Day Index" = _t, #"Current Week Index" = _t, #"Current Month Index" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date ID", Int64.Type}, {"Current Day Index", Int64.Type}, {"Current Week Index", Int64.Type}, {"Current Month Index", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date ID"}, "Attribute", "Value"), #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] = 1)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute", "Timeframe"}}) in #"Renamed Columns"Kind regards,
Rohit
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂
rohit_singh
4 years agoSolution Sage
Hi jludwick ,
You simply need to unpivot all columns except the date ID column, and then filter out values in column value that are <> 1.
Here is the sample M-code. you can copy and paste this into a blank query and see all the steps in detail.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjIwMzRR0lEyAGJDMI7VgUuY4pIwgwuCJWIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date ID" = _t, #"Current Day Index" = _t, #"Current Week Index" = _t, #"Current Month Index" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date ID", Int64.Type}, {"Current Day Index", Int64.Type}, {"Current Week Index", Int64.Type}, {"Current Month Index", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date ID"}, "Attribute", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] = 1)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute", "Timeframe"}})
in
#"Renamed Columns"
Kind regards,
Rohit
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂
- jludwick4 years agoFrequent Visitor
Thank you Rohit!