简体   繁体   English

嵌套组中的SSRS总和

[英]SSRS Sum in nested groups

I have a table with Year, Month, Product, and number of attempts and number of successful attempts. 我有一个表,其中包含年,月,产品,尝试次数和成功尝试次数。

Data is grouped by Year, then Month and then Product. 数据按年份,月份和产品分组。

I need to add %success (successful/attempts) by Product, and then for the grouping by Month and then by Year. 我需要按产品添加%成功(成功/尝试),然后按月份再按年份进行分组。

Before I had year and month in one field. 在我一个月又一个月地工作之前。 So I was able to do this using Sum(success.value,"period")/Sum(attempts.value,"period"). 因此,我能够使用Sum(success.value,“ period”)/ Sum(attempts.value,“ period”)来执行此操作。

But how is this done if there are nested groups? 但是,如果有嵌套组,该怎么办?

I did see something about adding the parameter "recursive", but haven't got it to work yet. 我确实看到了有关添加参数“递归”的信息,但尚未使它起作用。

Aggregation happens implicitly within the scope of the current level. 聚合隐式地发生在当前级别的范围内。 Normally =SUM(Fields!Amount.Value) is all that is required and Reporting Services handles the aggregation automatically. 通常, =SUM(Fields!Amount.Value) ,Reporting Services会自动处理聚合。

If you have the following grouping, here is how the aggregation works implicitly if you just use =SUM(Fields!Amount.Value) : 如果您具有以下分组,则仅使用=SUM(Fields!Amount.Value) ,聚合=SUM(Fields!Amount.Value)隐式工作:

Year    Month    Product    Aggregation
2013                        Sums all products for all months for 2013
        January             Sums all products for January 2013
                 Widget     Sums all Widgets for January 2013
                 Gadget     Sums all Gadgets for January 2013
        February            Sums all products for February 2013 
                 Widget     Sums all Widgets for February 2013
                 Gadget     Sums all Gadgets for February 2013
2014                        Sums all products for all months for 2014
        January             Sums all products for January 2014
                 Widget     Sums all Widgets for January 2014
                 Gadget     Sums all Gadgets for January 2014
        February            Sums all products for February 2014 
                 Widget     Sums all Widgets for February 2014
                 Gadget     Sums all Gadgets for February 2014

In your case implicit aggregation should work fine regardless of the amount of nesting - Reporting Services will work it all out for you. 在您的情况下,无论嵌套的数量如何,隐式聚合都可以正常工作-Reporting Services将为您全力以赴。 So this expression should work at every level of grouping: 因此,此表达式应适用于分组的每个级别:

=Sum(Fields!Success.Value) / Sum(Fields!Attempts.Value)

The SUM will be performed within the scope of the current level of grouping implicitly. SUM将在当前分组级别的范围内隐式执行。 If this is not happening, you probably have your grouping operating incorrectly. 如果这没有发生,则可能是您的分组操作不正确。 Have a look at the group properties and see what that level of grouping is actually grouping on; 看一下组属性,看看该分组实际上是在什么级别上进行分组的; the outer group should be Year, the next group Month and the final innermost group Product. 外部组应为Year,下一个组Month和最后一个最内层的Product。

This doesn't group all Januarys together, it signifies that when that field changes it should print a group footer for the previous group and a group header for the next group. 这不会将所有的一月进行分组,它表示当该字段更改时,它应该为上一个组打印一个组页脚,为下一个组打印一个组页眉。 In 2013 when January changes to February it triggers a group change and similarly when January changes to February in 2014. Different Januarys, within the scope of the higher level grouping of the Year. 在2013年1月更改为2月时,会触发组更改; 2014年1月更改为2月时,也会触发组更改。不同的1月,在Year较高级别的分组范围内。

You need to ensure that your data is in the order required for the grouping, either by using ORDER BY [Year], [Month], [Product] in your SQL statement or by implementing sorting on your tablix. 您需要通过在SQL语句中使用ORDER BY [Year], [Month], [Product]或对Tablix进行排序,来确保数据按分组所需的顺序排列。 Otherwise fields won't be in the right order and group changes will be triggered constantly as the fields are in random orders. 否则,字段的顺序将不正确,并且由于字段的顺序随机,组更改将不断触发。

You only need to define the scope explicitly if you are aggregating outside the current scope. 如果要在当前作用域之外进行聚合,则只需要显式定义作用域。 For example, if I want to add the percentage that each row is of the total of the dataset, then I need to explicitly use the dataset as my scope for aggregation, so I would use this calculation in my detail row: 例如,如果要添加每行占数据集总数的百分比,则需要显式使用数据集作为聚合范围,因此我将在详细行中使用此计算:

=SUM(Fields!Amount.Value) / SUM(Fields!Amount.Value, "MyDataset")

Note that the recursive parameter is only used for tables that have hierarchical data - that is, parent/child relationships such as an organisational chart of employees. 请注意, 递归参数仅用于具有层次结构数据的表,即父/子关系,例如员工的组织结构图。

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

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