Month Sorting

I have a column chart that uses grouping by month on the x-axis. The datasource field is an SSAS time dimension-month heirarchy (string).The problem is when I try and sort by month (Jan, Feb, March, April, etc) it sorts as a string (April, Feb, Jan, etc). How would I format the sorting to show the proper month order. Thanks

November 19th, 2008 4:49pm

u need to add one more column called month_number or something which is like number:

select datepart(mm, getdate())

u can then sort it by this number and it will work fine.

regards,

vijay

Free Windows Admin Tool Kit Click here and download it now
November 19th, 2008 5:16pm

Vijay,

Is there anyway to do this kind of sorting on the fly within SSRS as I am using an SSAS datasource rather than a SQL datasource.

What I am looking for is howtoformat a month string, within RS, so that it is read as a month and can be sorted according to month (Jan, Feb, March, etc) instead of alphabetically.

Thanks for your help.

November 19th, 2008 5:27pm

This code snipet returns the month as a number... ideally you want to be passing this value to your chart.

select month(getdate())
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2008 5:50pm

You could use the following expression within SSRS to convert the month in string format to an integer:

=Month(CDATE(Fields!MonthField.Value + ", 01, 2008"))

hope this helps,

sivilian

November 19th, 2008 6:11pm

Jon,

I am using an SSAS datasource, not a SQL datasource for my reports. I want to know how to format the month string, within RS, to an int (Jan is 1 and Feb is 2) to be able to sort on that.

So, how would I format let's say Month(Format(Fields!Month_Display.Value)) into an int representation ofmonth ...... Month_Display is the string for month (Jan, Feb, March, etc).

I think what you are trying to tell me is how my query must sort the Months, but I am using an SSAS datasource, which already has the months stored within the dimension as a heirarchy.

Thanks a bunch for your help!!

Free Windows Admin Tool Kit Click here and download it now
November 19th, 2008 6:14pm

Sivilian,

That's what I needed, thanks a bunch!!!!

November 19th, 2008 6:16pm

Just found another easy way to do this....

Go to the "Month" Group properties and then to the sorting. By default the sort column is by [Month] and order by A-Z. select and delete the sort option so that you will not see any sort options for the particular group.

Then the report runs as a charm.
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2011 5:55pm

Optionally. right click on rdl file on the solution and choose. show code option. there will be an xml displayed. search for "month" until you end up something like below. you should remove these tags and it will work like a charm.

 <SortExpressions>
                    <SortExpression>
                      <Value>=Fields!MonthName.Value</Value>
                    </SortExpression>
                  </SortExpressions>

February 19th, 2015 9:52am

The Best Solution!
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 11:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics