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

Sorting Version Number with multiple decimal points formatted as text

 

 

I am trying to sort Version numbers that will be displayed on a graph and I am running into the infamous sorting where 2.0.10.0 does not come after 2.0.9.0 because it looks at 1 vs 9 (See Below)  I cannot convert to numeric because of the number of decimals.  Anyone have any suggestions?  I have thought of creating a new column and parsing through to 3rd set and pad with 0 for values with a len of 1 for sorting purposes, but making that happen has been tougher than my beginner skills have conquered.  I originally made a static table with versions and sort value but that had to be edited manually with each version change making it a pain for reporting.   Need something dynamic.

 

Version.JPG

2 ACCEPTED SOLUTIONS
MFelix
Super User
Super User

Hi @pchilton,

 

Do the following steps on advance query editor:

 

  • Add a custom column based on Version number
  • Split the new column by Delimiter "."
  • Add a new custom column with the following code:

 

Text.PadStart ([Valid.1], 2, "0") & "." &
Text.PadStart ([Valid.2], 2, "0") & "." &
Text.PadStart ([Valid.3], 2, "0") & "." &
Text.PadStart ([Valid.4], 2, "0")
  • Sort by new column
  • Delete Columns created with split delimiter

See below the M Code for a Query editor so you can replicate and look at what I did.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIz0DM00DNQitWBcIz1DA2ROEZGcI4JkioTPWM42xIkHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Version = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Version", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Valid", each [Version]),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Valid", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Valid.1", "Valid.2", "Valid.3", "Valid.4"}),
    #"Added Custom1" = Table.AddColumn(#"Split Column by Delimiter", "Sort_Version", each Text.PadStart ([Valid.1], 2, "0") & "." &
Text.PadStart ([Valid.2], 2, "0") & "." &
Text.PadStart ([Valid.3], 2, "0") & "." &
Text.PadStart ([Valid.4], 2, "0")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Valid.1", "Valid.2", "Valid.3", "Valid.4"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Sort_Version", Order.Ascending}})
in
    #"Sorted Rows"

 

I assumed that you only go to 2 numbers in each part of the Version that why the Padding of the text for all columns is 2.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

Hi @pchilton,

 

On the desktop choose the original column Version and the:

 

  • Modeling
  • Sort By Column

In this option select the new Version column to sort the first one by this new one as you can see below the values are sort by default by the sort column.

 

sort.gif

 

Regards,

MFelix

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

12 REPLIES 12
MFelix
Super User
Super User

Hi @pchilton,

 

Do the following steps on advance query editor:

 

  • Add a custom column based on Version number
  • Split the new column by Delimiter "."
  • Add a new custom column with the following code:

 

Text.PadStart ([Valid.1], 2, "0") & "." &
Text.PadStart ([Valid.2], 2, "0") & "." &
Text.PadStart ([Valid.3], 2, "0") & "." &
Text.PadStart ([Valid.4], 2, "0")
  • Sort by new column
  • Delete Columns created with split delimiter

See below the M Code for a Query editor so you can replicate and look at what I did.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIz0DM00DNQitWBcIz1DA2ROEZGcI4JkioTPWM42xIkHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Version = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Version", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Valid", each [Version]),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Valid", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Valid.1", "Valid.2", "Valid.3", "Valid.4"}),
    #"Added Custom1" = Table.AddColumn(#"Split Column by Delimiter", "Sort_Version", each Text.PadStart ([Valid.1], 2, "0") & "." &
Text.PadStart ([Valid.2], 2, "0") & "." &
Text.PadStart ([Valid.3], 2, "0") & "." &
Text.PadStart ([Valid.4], 2, "0")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Valid.1", "Valid.2", "Valid.3", "Valid.4"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Sort_Version", Order.Ascending}})
in
    #"Sorted Rows"

 

I assumed that you only go to 2 numbers in each part of the Version that why the Padding of the text for all columns is 2.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi,

 

I have a Rule_Name column which is a text field that I want to have it sorted based on 2.1...,2.2...,2.3....,18.1...,19.1....
For it first I tried to do text before delimiter to remove these number from the Rule_Name column into a new column. However, this "Text Before Delimiter" column is also a text column and I am not able to sort in correct. Could you please assist me with this?

umarfarooq4_1-1683730919500.png

 

 

Thanks,

 

Umar

Hi @umarfarooq4 

 

Try to add the following custom colum:

Text.PadStart(Text.BeforeDelimiter([Rule_Name], ".", 0), 3, "0")
  & "."
  & Text.PadStart(
    Text.BeforeDelimiter(Text.AfterDelimiter([Rule_Name], ".", 0), ".", 0), 
    3, 
    "0"
  )
  & "."
  & Text.PadStart(
    Text.BeforeDelimiter(
      Text.BeforeDelimiter(Text.AfterDelimiter([Rule_Name], ".", 1), ".", 1), 
      ".", 
      0
    ), 
    3, 
    "0"
  )
  & "."
  & Text.PadStart(Text.AfterDelimiter( Text.BeforeDelimiter( [Rule_Name] , " ") , ".", 2), 3, "0")

 

Result below:

MFelix_0-1683833155119.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you, that worked!  I appreciate your assistance.

 

Now I am working on displaying the original format in the sorted order in the visual.  Smiley Happy  Always something to learn.

Hi @pchilton,

 

On the desktop choose the original column Version and the:

 

  • Modeling
  • Sort By Column

In this option select the new Version column to sort the first one by this new one as you can see below the values are sort by default by the sort column.

 

sort.gif

 

Regards,

MFelix

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



I have a Categorical Line Chart where the Axis is a version number, the legend is the type of Exception and the values are the count of the exception Id's so that we can see what types of exceptions become more and less frequent in each version.

 

I can create this chart but am having trouble sorting the Axis by increasing version number. I followed your instructions and now my dataset has a column containing the sortable version string, however it does not appear in the charts "Sort by" menu, which may have to do with the grouping/counting behavior.

Hi @KyleB ,

 

Are you using that new column as you x-axis on your visual?

 

The Sort by on the visuals only takes into account information on the values, legends or axis.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



If I place my zero padded tool_version_sortable column on the Axis I can sort by it. However, we have many versions and I would like to display the un-padded values sorted by the padded ones for visual compactness. Adding both columns to the axis does not make this possible either.

 

My latest attempt at achieving this behavior is to create a new table from my runs table that has only version numbers and padded version numbers and then add a relation connecting it to the other table. I was hoping that if I placed version number on the axis the many-to-one relation would allow me to sort by the padded versions

Hi @KyleB ,,

 

You need to sort the column you want to have in your visual by the one that as the padded version numbers.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix 

 

If I want to sort version numbers with upto 4 digits between the delimiters like the following numbers. Will the dax query work by just changing the padding number?

 

Text.PadStart ([Valid.1], 4, "0") & "." &
Text.PadStart ([Valid.2], 4, "0") & "." &
Text.PadStart ([Valid.3], 4, "0") & "." &
Text.PadStart ([Valid.4], 4, "0")

 

Example: 

WlanDriverVersion
20.70.4.2
19.51.15.3
15.16.0.2
2023.70.306.2018
20.70.6.1
19.51.8.3
3.0.2.201
15.68.9120.47
2024.0.3.101

 

Hi @srelwani ,

 

I have made a gif image with the steps to make the sort order work with the padded column, in my example I only have two columns (version and the padded one (using your formula).

 

You need to select the version and then a sort by the other column as you can the numbers get sorted by the padded and not by the defautl text values from the unpadded column, after this change this works for sorting any visual by the version.

 

Sorting.gif

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you again! Problem solved.

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.

Top Solution Authors