Forum Discussion
Sorting Version Number with multiple decimal points formatted as text
- 8 years ago
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
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.
Regards,
MFelix