Thursday, October 9, 2014

Dealing with version numbers in reports

If you've tried creating a installed software report of some sort you've probably experienced that sorting by version number rarely work as you expect.
The problem is that SSRS looks at version numbers as decimals ,so Java 7 Update 9 (7.0.90) comes after Java Update 67 (7.0.670) when you sort them.



To fix this you need to split the version number ,convert them from strings to integers ,then sort on each of the segments.
First things first ,in your query create one calculated field for each segment in the version number you're trying to sort. For Java create 3 fields(7.0.670) ,for Flash Player create 4 fields.(15.0.0.167).
In each calulated field add the following expression ,incrementing the number in the last parentheses :

=CInt(Split(Fields!Version0.Value,".")(0))



You don't have to display these version number fragments in your charts and tables ,but you can still use them for sorting.
On the element you want to sort ,just add all version number fields in sequence like this:


Now your software should be sorted correctly:





.....as you can see this works for charts to:


Hope this helps....













No comments:

Post a Comment