Crystal Reports 2008 - 非加性公式字段摘要
如果这个问题已经得到解答,我深表歉意;它可能有,但我在一个多小时的谷歌和SO搜索中还没有找到它。
我有一个非累加公式字段(成本/数量
)。它在详细信息行上运行良好,但当我将其添加到组页脚时,它返回最后一个详细信息行的值,而不是组级计算。我需要做什么才能对组中的所有行计算公式?我很惊讶这不是将字段添加到组页眉或页脚时的默认行为。
我得到的结果如下:
Category Cost Qty Avg Cost
Detail A-1 $100 1 $ 100
Detail A-2 $200 3 $ 67
Footer A $300 4 $ 67
我预计在页脚中看到的平均成本为 75 美元:300 美元/4。如果我使用聚合,我会得到一个不正确的值(例如,总和为 167 美元,平均为 83 美元)。在 Cognos 中,我使用“表达式”作为聚合公式。
有经验的 CR 用户可以告诉我我需要做什么吗?
My apologies if this has been answered already; it probably has, but I haven't found it in over an hour of Google and SO searching.
I have a non-additive formula field (Cost / Qty
). It works fine on detail rows, but when I add it to my group footers, it returns the values from the last detail row rather than a group-level calculation. What do I need to do to get the formula evaluated upon all the rows in a group? I'm surprised this isn't default behavior when adding a field to a group header or footer.
Here's what I'm getting:
Category Cost Qty Avg Cost
Detail A-1 $100 1 $ 100
Detail A-2 $200 3 $ 67
Footer A $300 4 $ 67
I expect to see an Avg Cost of $75 in the footer: $300 / 4. If I used an aggregate I'd get an incorrect value (e.g., $167 for Sum, $83 for Avg). In Cognos, I'd use "Expression" as my aggregation formula.
Can some experienced CR user please tell me what I need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须仅为报表页脚创建一个新的公式字段。
因此,如果您的详细公式如下所示:
{Test.Cost} / {Test.Qty}
那么您需要使用以下内容创建新公式:
Sum ({Test.Cost}) / Sum ({Test.Qty})
并将其放置在报告页脚中。这将返回正确的平均值 ( 300 / 4 = 75 )
编辑:
如果您想对组页脚执行此操作,则适用类似的原则。您必须创建一个新的公式字段并将其添加到组页脚。
例如,如果您按“类别”字段进行分组,则计算该组平均值的公式将如下所示:
Sum ({Test.Cost}, {Test.Category}) / Sum({测试.数量},{测试.类别})
You have to create a new formula field just for the Report Footer.
So if your detail formula is like this:
{Test.Cost} / {Test.Qty}
Then you need to create new formula with the following:
Sum ({Test.Cost}) / Sum ({Test.Qty})
and place it in the Report Footer. This will return the correct average ( 300 / 4 = 75 )
EDIT:
If you want to do this for a Group Footer a similar principle applies. You have to create a new formula field and add it to the Group Footer.
If you were grouping by the
Category
field for instance then your formula to calculate the average over the group would look like this:Sum ({Test.Cost}, {Test.Category}) / Sum ({Test.Qty}, {Test.Category})