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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

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

@Anonymous 

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

Anonymous
Not applicable

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
Anonymous
Not applicable

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

@Anonymous 

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors