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

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.

Reply
jludwick
Frequent 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 IDCurrent Day IndexCurrent Week IndexCurrent Month Index
202206140

1

1
20220615011
20220616111

 

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 IDTimeframe
20220614Current Week
20220614Current Month
20220615Current Week
20220615Current Month
20220616Current Week
20220616Current Month
20220616Current Day

 

Am I able to build something like this using the "New Table" option and building it via DAX formulas?

1 ACCEPTED SOLUTION
rohit_singh
Solution Sage
Solution 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. 

rohit_singh_0-1655415139605.png

 

rohit_singh_1-1655415152262.png

rohit_singh_2-1655415166886.png

rohit_singh_3-1655415177017.png


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! 🙂

View solution in original post

2 REPLIES 2
rohit_singh
Solution Sage
Solution 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. 

rohit_singh_0-1655415139605.png

 

rohit_singh_1-1655415152262.png

rohit_singh_2-1655415166886.png

rohit_singh_3-1655415177017.png


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! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.