如何在Crystal Reports中有条件地分组项目?

时间:2022-08-19 16:38:58

I have a report that is currently separated into two reports, and I'd like to merge them.

我有一个报告,目前分为两个报告,我想合并它们。

Basically it boils down to this:

基本上它归结为:

I ask the user if they want to have a page break for each Property, if they answer yes, I sort/group by Property and then I sort by X
If the user answers no, I want to just sort/group by X

我问用户是否要为每个属性分页,如果他们回答是,我按属性排序/分组然后我按X排序如果用户回答否,我想只按X排序/分组

I've tried suppressing the initial Grouping if the user answers No, but it still sorts accordingly (not how I want it to).

如果用户回答“否”,我已经尝试抑制初始分组,但它仍然相应地排序(不是我想要的)。

How can I do this without keeping it in two reports?

如何在不将其保存在两份报告中的情况下执行此操作?

2 个解决方案

#1


Instead of suppressing the grouping field, try setting it to an empty string "". I was just working on a report last week that was very similar. Even if 'no grouping' was selected, the report was still being grouped by some unknown default. In the formula grouping field, I found that if 'no grouping' was selected the field was not getting set at all. Once I changed it to set the field to an empty string, the report generated as expected.

尝试将其设置为空字符串“”,而不是抑制分组字段。我上周正在编写一份非常相似的报告。即使选择了“无分组”,报告仍按一些未知的默认值进行分组。在公式分组字段中,我发现如果选择“无分组”,则字段根本没有设置。一旦我更改它以将字段设置为空字符串,报告将按预期生成。

#2


Are you grouping or sorting? If you do not use the group header/footer it is basically the same as sorting and you should simply use the record sort.

你在分组或排序吗?如果您不使用组页眉/页脚,它基本上与排序相同,您应该只使用记录排序。

In general, to conditionally group fields you would use formulas. For this to work the fields in question need to be returned as the same type: number, string, date, etc. In your case it sounds like the first grouping formula would be like this...

通常,要有条件地对字段进行分组,您将使用公式。为了使这个工作,有问题的字段需要返回相同的类型:数字,字符串,日期等。在你的情况下,它听起来像第一个分组公式将是这样的......

//{?break_by_property} would be the parameter value to control the page break

if {?break_by_property) then
{the_property_field}
else
"" //any static value of the same type as {the_property_field}

now go the "new page before" formula for that group header and enter this boolean formula (groupnumber is a special keyword)...

现在进入该组头的“新页面”公式并输入此布尔公式(groupnumber是一个特殊关键字)...

{?break_by_property} and groupnumber > 1

then add a record sort for X.

然后为X添加记录排序。

#1


Instead of suppressing the grouping field, try setting it to an empty string "". I was just working on a report last week that was very similar. Even if 'no grouping' was selected, the report was still being grouped by some unknown default. In the formula grouping field, I found that if 'no grouping' was selected the field was not getting set at all. Once I changed it to set the field to an empty string, the report generated as expected.

尝试将其设置为空字符串“”,而不是抑制分组字段。我上周正在编写一份非常相似的报告。即使选择了“无分组”,报告仍按一些未知的默认值进行分组。在公式分组字段中,我发现如果选择“无分组”,则字段根本没有设置。一旦我更改它以将字段设置为空字符串,报告将按预期生成。

#2


Are you grouping or sorting? If you do not use the group header/footer it is basically the same as sorting and you should simply use the record sort.

你在分组或排序吗?如果您不使用组页眉/页脚,它基本上与排序相同,您应该只使用记录排序。

In general, to conditionally group fields you would use formulas. For this to work the fields in question need to be returned as the same type: number, string, date, etc. In your case it sounds like the first grouping formula would be like this...

通常,要有条件地对字段进行分组,您将使用公式。为了使这个工作,有问题的字段需要返回相同的类型:数字,字符串,日期等。在你的情况下,它听起来像第一个分组公式将是这样的......

//{?break_by_property} would be the parameter value to control the page break

if {?break_by_property) then
{the_property_field}
else
"" //any static value of the same type as {the_property_field}

now go the "new page before" formula for that group header and enter this boolean formula (groupnumber is a special keyword)...

现在进入该组头的“新页面”公式并输入此布尔公式(groupnumber是一个特殊关键字)...

{?break_by_property} and groupnumber > 1

then add a record sort for X.

然后为X添加记录排序。