Sorting by year and monthname

青春壹個敷衍的年華 提交于 2019-12-11 03:56:30

问题


I am building a report using Report Builder 3.0. I am grouping by Month, but the Month field in my cube is in the format "2013 November". It looks good, but it sorts alphabetically instead of in calendar order.

During my searching I found this page http://timyocum.blogspot.co.nz/2012/02/sorting-by-date-not-alphabetically-by.html

It has the right idea, but it doesn't work for the format of my data.

Can anyone help me figure this out?

Thanks

David


回答1:


Sort by an expression:

=CDate(Fields!Month.Value)

This works OK for data in your format, even if it's a string. The expression converts the string to a date which can be sorted correctly,

I have some sample string-based data:

select Month = '2013 October'
union all select Month = '2013 November'
union all select Month = '2013 December'

A simple table based on this:

Sort by [Month]:

Sort by =CDate(Fields!Month.Value):

As per the blog post you include, you could also easily move the date conversion to a calculated field and sort by that, which could be useful if you're using it in multiple places.



来源:https://stackoverflow.com/questions/19780598/sorting-by-year-and-monthname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!