简体   繁体   English

在SSRS中,如何对多个组求和?

[英]In SSRS, how can I SUM by multiple groups?

Please refer to the below table: 请参考下表:

+----------------------------------------------------------+
| +-----------+--------------------+---------------------+ |
| | Company   | GL Account         | Amount              | |
| +-----------+--------------------+---------------------+ |
| | Company 1 | Cash at Bank ANZ   | $500,452.22         | |
| +-----------+--------------------+---------------------+ |
| |           | Westpac Investment | $443,233.32         | |
| +-----------+--------------------+---------------------+ |
| |           | NAB Cheque         | $9,833.22           | |
| +-----------+--------------------+---------------------+ |
| | Company 2 | Cash at Bank ANZ   | $938.22             | |
| +-----------+--------------------+---------------------+ |
| |           | Investment Online  | $940,404,400.20     | |
| +-----------+--------------------+---------------------+ |
| | Company 3 | Online Advantage   | $93,393.00          | |
| +-----------+--------------------+---------------------+ |
| |           | Direct Access      | $30.30              | |
| +-----------+--------------------+---------------------+ |
| |           | BAR Invest         | $192,330,303,300.10 | |
| +-----------+--------------------+---------------------+ |
| | TOTAL     |                    | $193,271,755,580.58 | |
| +-----------+--------------------+---------------------+ |
+----------------------------------------------------------+

This above table is what my SSRS report currently looks like. 上表是我的SSRS报告当前的样子。 As you can see, I have a group of companies. 如您所见,我有一组公司。 Each company has GL Accounts with multiple transactions however, I am only displaying the total for each GL account. 每个公司的总帐帐户都有多个交易记录,但是,我只显示每个总帐帐户的总数。 For example, the top amount field "$500,452.22" is a total of ALL transactions for "Cash at Bank ANZ" for "Company 1". 例如,最高金额字段“ $ 500,452.22”是“公司1”的“银行ANZ现金”的所有交易的总计。 Furthermore, I have a total at the bottom, which is the total of ALL amount totals. 此外,我在底部有一个总计,它是ALL总计的总计。

I want to add an additional total field which shows the total for ALL amounts fore each company. 我想添加一个额外的总计字段,该字段显示每个公司的所有金额的总计。 Basically, the report should look like this: 基本上,报告应如下所示:

+----------------------------------------------------------+
| +-----------+--------------------+---------------------+ |
| | Company   | GL Account         | Amount              | |
| +-----------+--------------------+---------------------+ |
| | Company 1 | Cash at Bank ANZ   | $500,452.22         | |
| +-----------+--------------------+---------------------+ |
| |           | Westpac Investment | $443,233.32         | |
| +-----------+--------------------+---------------------+ |
| |           | NAB Cheque         | $9,833.22           | |
| +-----------+--------------------+---------------------+ |
| |           | TOTAL              | $953,518.76         | |
| +-----------+--------------------+---------------------+ |
| | Company 2 | Cash at Bank ANZ   | $938.22             | |
| +-----------+--------------------+---------------------+ |
| |           | Investment Online  | $940,404,400.20     | |
| +-----------+--------------------+---------------------+ |
| |           | TOTAL              | $940,405,338.42     | |
| +-----------+--------------------+---------------------+ |
| | Company 3 | Online Advantage   | $93,393.00          | |
| +-----------+--------------------+---------------------+ |
| |           | Direct Access      | $30.30              | |
| +-----------+--------------------+---------------------+ |
| |           | BAR Invest         | $192,330,303,300.10 | |
| +-----------+--------------------+---------------------+ |
| |           | TOTAL              | $192,330,396,723.40 | |
| +-----------+--------------------+---------------------+ |
| | TOTAL     |                    | $193,271,755,580.58 | |
| +-----------+--------------------+---------------------+ |
+----------------------------------------------------------+

Every time I try to create this total field, the report just displays duplicates of each GL Account total and not the total of all amounts per company. 每次我尝试创建此总计字段时,报告仅显示每个总帐帐户总计的重复项,而不显示每个公司所有金额的总计。

Can anyone explain how to add the field that I want? 谁能解释如何添加我想要的字段?

FYI: This is the SQL Query that I used: 仅供参考:这是我使用的SQL查询:

select GLAC.GLCo as Company, HQCO.Name as 'Company Name', GLAC.Description as 'GL Description', GLDT.Amount as Amount from GLAC 

    LEFT JOIN HQCO ON
    GLAC.GLCo = HQCO.HQCo
    LEFT JOIN GLDT ON
    GLAC.GLCo = GLDT.GLCo and GLAC.GLAcct = GLDT.GLAcct
    where udCategory = 'Cash At Bank' and Active = 'Y'  and (GLAC.GLCo = 1 or GLAC.GLCo = 5 or GLAC.GLCo = 6 or GLAC.GLCo = 7)

Managing groups went from really simple in SSRS 2005 to very difficult and arcane in SSRS 2008. Adding a footer to a group is the least intuitive UX ever. 管理组从SSRS 2005中的非常简单到SSRS 2008中的非常困难和奥秘。向组中添加页脚是有史以来最不直观的UX。

To create a header or footer after the group has been created, go to the bottom of the design window where the Row Groups panel is. 要在创建组后创建页眉或页脚,请转到“ Row Groups面板所在的设计窗口的底部。 This will show your groups. 这将显示您的组。 Drop down the arrow on the Detail group (not the actual group you want to add the footer to but the group inside that) and you will see Add Total with a menu of Before or After . 将箭头拖到“ Detail组(不是要向其中添加页脚的实际组,而是要向其中添加的组)上,您将看到“ Add Total和一个“ Before或“ After菜单。 Before adds a header and After adds a footer to the group that encloses the item you are adding the total to. Before添加页眉, After添加页脚到将要添加总计的组中。

Once the footer has been created put the expression =SUM(Fields!Amount.Value) into the column and it will sum the amount for your group. 创建页脚后,将表达式=SUM(Fields!Amount.Value)放入列中,它将为您的组总计。

If I recall correctly there is an option in SSRS 2008 R2 to add group sub-totals to a tablix when you add the group. 如果我没记错的话,在添加组时,SSRS 2008 R2中有一个选项可以将组小计添加到tablix。

If you're trying to add them after the fact you can create a group footer row and then put your =SUM(Field!Amount.Value) in the Amount column and just hardcode the TOTAL text in the GL Account column. 如果要在事实之后添加它们,可以创建一个组页脚行,然后将=SUM(Field!Amount.Value)放入“金额”列中,然后在“总帐科目”列中硬编码“ TOTAL文本。 Since this is still being done inside the scope of the grouping it will only SUM() the values for that group. 由于仍在分组范围内进行,因此它将仅对该组的值进行SUM()运算。

I think that , the 'Total' that you are looking will be equal to the sum of all Amount in the data set. 我认为,您正在查找的“总计”将等于数据集中所有金额的总和。 I think this should work. 我认为这应该有效。

 1. Add a subtotal row   
 2. List item give its expression as SUM(Field!Amount.value)

Grouping in SSRS is certainly not intuitive. SSRS中的分组当然不是直观的。

I managed to achieve what I wanted by right clicking in the "Amount" field and then selecting "Insert Row" --> "Outside Group (Below)". 通过右键单击“金额”字段,然后选择“插入行”->“外部组(如下)”,我设法实现了所需的功能。 I then put the sum in the new cell and everything was calculated how I desired. 然后,我将总和放入新的单元格中,然后按照我想要的方式计算了所有内容。

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

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