Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 Month Index |
20220614 | 0 | 1 | 1 |
20220615 | 0 | 1 | 1 |
20220616 | 1 | 1 | 1 |
I want to create a new table that will have every single date for each index column that equals 1. For example, June 16th (today), is the current day, within the current week, and within the current month-- so I should have 3 instances of today's date along with the "Timeframe" description in the other column. Example of how my table should look:
[Date Hierarchy]
Date ID | Timeframe |
20220614 | Current Week |
20220614 | Current Month |
20220615 | Current Week |
20220615 | Current Month |
20220616 | Current Week |
20220616 | Current Month |
20220616 | Current Day |
Am I able to build something like this using the "New Table" option and building it via DAX formulas?
Solved! Go to Solution.
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! 🙂
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! 🙂
Thank you Rohit!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
105 | |
88 | |
73 | |
66 |
User | Count |
---|---|
124 | |
113 | |
98 | |
80 | |
72 |