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
Friedrich
Frequent Visitor

Generate a rank column with dates for related table

Hello to everyone.

I want to create a column where the dates of the related table are shown in ranked ascending order. I want to do it with a measure, because of further slicer use. I mention a unrelated rank table (1, 2, 3 ...) where the dates are filtered and are shown ranked ascending.

Thanks for the help.

Best regards

 

Problem_Rank_Dates.jpg

 

3 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@Friedrich 

You can do in Power Query.

This is my source data which is similar to your Table 2.

Fowmy_0-1595857850548.png


The output you are expecting:

Fowmy_1-1595857908828.png


Paste this code in a blank query, go to the advanced editor, clear everything, and paste. You can check the steps I performed to so the transformation.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIw1AUiIwOlWB2ogBG6gDGSgBG6FpCAoQGSgDFEhW9iJYJrBuHGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store ID" = _t, Dates = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dates", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Store ID"}, {{"Count", each _, type table [Store ID=nullable text, Dates=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Count][Dates]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), "|"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"Custom.1", "1"}, {"Custom.2", "2"}, {"Custom.3", "3"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Count"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"1", type date}, {"2", type date}, {"3", type date}})
in
    #"Changed Type1"

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

I accept KUDOS 🙂

YouTube, LinkedIn



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

andre
Memorable Member
Memorable Member

You are basically trying to PIVOT your date column based on ranking... here is a video that will walk you through how to do it.  It has a very similar table dsign as what you used in your example:

if you want to see the calculations, you can download the Power BI Desktop file here:

https://businessintelligist.com/2020/07/27/power-bi-dax-tutorial-how-to-pivot-data-using-dax-using-r...

 

 

View solution in original post

Friedrich
Frequent Visitor

Hello,

i solved it this way.

Best regards 

tablestables

 

power pivot tablepower pivot table

 

measure datesmeasure dates

 

measure datediffmeasure datediff

 

View solution in original post

3 REPLIES 3
Friedrich
Frequent Visitor

Hello,

i solved it this way.

Best regards 

tablestables

 

power pivot tablepower pivot table

 

measure datesmeasure dates

 

measure datediffmeasure datediff

 

andre
Memorable Member
Memorable Member

You are basically trying to PIVOT your date column based on ranking... here is a video that will walk you through how to do it.  It has a very similar table dsign as what you used in your example:

if you want to see the calculations, you can download the Power BI Desktop file here:

https://businessintelligist.com/2020/07/27/power-bi-dax-tutorial-how-to-pivot-data-using-dax-using-r...

 

 

Fowmy
Super User
Super User

@Friedrich 

You can do in Power Query.

This is my source data which is similar to your Table 2.

Fowmy_0-1595857850548.png


The output you are expecting:

Fowmy_1-1595857908828.png


Paste this code in a blank query, go to the advanced editor, clear everything, and paste. You can check the steps I performed to so the transformation.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIw1AUiIwOlWB2ogBG6gDGSgBG6FpCAoQGSgDFEhW9iJYJrBuHGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store ID" = _t, Dates = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dates", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Store ID"}, {{"Count", each _, type table [Store ID=nullable text, Dates=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Count][Dates]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), "|"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"Custom.1", "1"}, {"Custom.2", "2"}, {"Custom.3", "3"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Count"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"1", type date}, {"2", type date}, {"3", type date}})
in
    #"Changed Type1"

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

I accept KUDOS 🙂

YouTube, LinkedIn



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.