简体   繁体   English

在 Crystal Reports 中对交叉表列进行排序

[英]Sorting Cross-Tab columns in Crystal Reports

I've been working in a Crystal Reports project where I have to show a sum of values gruped in columns by months.我一直在一个 Crystal Reports 项目中工作,在该项目中我必须按月显示按列分组的值的总和。

I've to proccess a range of a year from the specified date in parameters.我必须从参数中的指定日期开始处理一年的范围。 So I've used Cross-Tabs, grouping by columns of @MONTH_DISPLAY, defined by: month({ASIENTOI.DATE}).所以我使用了交叉表,按@MONTH_DISPLAY 的列分组,定义为:month({ASIENTOI.DATE})。 The important fact is that I've to sort columns by the earliest month to a year from it.重要的事实是,我必须按最早的月份到一年对列进行排序。 Which means: If the user set the date by 10-07-12, I've to show colums sorted like this: July (2012) - ... - June (2013).这意味着:如果用户将日期设置为 10-07-12,我必须显示这样排序的列:七月 (2012) - ... - 六月 (2013)。

The problem is that Crystal Reports set that range like this: Jan (2013) - ... - June (2013) - July (2012) - ... - December (2012).问题是 Crystal Reports 设置的范围是这样的:Jan (2013) - ... - June (2013) - July (2012) - ... - December (2012)。

And I just can't find the way to get that sorting modified.我就是找不到修改排序的方法。

The only way to sort cross-tab columns via designer is choosing between descending or ascending order, this means crystal report will order your fields by alphabetical order.通过设计器对交叉表列进行排序的唯一方法是在降序或升序之间进行选择,这意味着水晶报表将按字母顺序对您的字段进行排序。

A possible workaround is, for example, putting numbers with an underscore before the string you want to order in your datasource (like 01_July (2012), 02_August (2012)...13_June (2013)) and use the order ascending, then to hide the numbers, go in the "cross-tab expert" section and on the cross-tab tab choose "group option" under the columns (sorry I only have it in Italian)例如,一种可能的解决方法是在数据源中要排序的字符串之前放置带下划线的数字(如 01_July (2012)、02_August (2012)...13_June (2013))并使用升序,然后到隐藏数字,进入“交叉表专家”部分,然后在交叉表选项卡上的列下选择“组选项”(对不起,我只有意大利语)组选项

and on the option tab choose the options below并在选项选项卡上选择以下选项

选项选项卡

click on the formula button and use the function单击公式按钮并使用该功能

Right(yourField,Length(yourField)-3)

to exclude the prefix so you will not have "01_July (2012)" on the cross-tab colum but "July (2012)".排除前缀,因此交叉表列上不会有“01_July (2012)”,而是“July (2012)”。 This should do the trick这应该可以解决问题

Another use-full workaround is.另一个有用的解决方法是。

create a new formula say column1 = ToText({yourField}, "yyyy") + '-' + ToText({yourField},"MM") .创建一个新公式column1 = ToText({yourField}, "yyyy") + '-' + ToText({yourField},"MM") use this field as cross tab column.将此字段用作交​​叉表列。

now your cross tab columns will be sorted as现在您的交叉表列将被排序为

2020-01 | 2020-02 | 2020-03 |...

now Cross-Tab expert> columns> Group Options > tab: Options > ✓ customize Group Name field > ✓ use a formula as group name.现在交叉表专家> 列> 组选项> 选项卡:选项> ✓ 自定义组名称字段> ✓ 使用公式作为组名称。

add Left({@column1}, 5) & MonthName(ToNumber(Right({@column1}, 2)),True) thus final outcome添加Left({@column1}, 5) & MonthName(ToNumber(Right({@column1}, 2)),True)因此最终结果

2020-Jan | 2020-Feb | 2020-Mar |...

sorted columns based on month date but printed by month name!根据月份日期对列进行排序,但按月份名称打印!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM