在SSRS中,如何通过多个组进行SUM?

时间:2014-05-26 00:24:30

标签: sql reporting-services sum

请参阅下表:

+----------------------------------------------------------+
| +-----------+--------------------+---------------------+ |
| | 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 | |
| +-----------+--------------------+---------------------+ |
+----------------------------------------------------------+

上表是我的SSRS报告目前的样子。 如您所见,我有一组公司。每家公司都有GL账户,有多个交易,但我只显示每个GL账户的总额。例如,最高金额字段" $ 500,452.22"是"现金银行ANZ"的全部交易。为"公司1"。此外,我总共在底部,这是所有总金额的总和。

我想添加一个额外的总字段,显示每个公司前所有金额的总额。基本上,报告应如下所示:

+----------------------------------------------------------+
| +-----------+--------------------+---------------------+ |
| | 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 | |
| +-----------+--------------------+---------------------+ |
+----------------------------------------------------------+

每次我尝试创建此总字段时,报表只显示每个总帐帐户总计的重复项,而不是每个公司所有金额的总和。

任何人都可以解释如何添加我想要的字段吗?

仅供参考:这是我使用的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)

4 个答案:

答案 0 :(得分:1)

管理小组从SSRS 2005中的非常简单到SSRS 2008中非常困难和晦涩。在组中添加页脚是迄今为止最不直观的用户体验。

要在创建组后创建页眉或页脚,请转到Row Groups面板所在的设计窗口的底部。这将显示您的群组。下拉Detail组上的箭头(不是您想要添加页脚的实际组,但不包括其中的组),您会看到Add Total的菜单为Before或{ {1}}。 After添加了一个标题,Before将一个页脚添加到包含要添加总计的项目的组中。

创建页脚后,将表达式After放入列中,它将为您的组添加总和。

答案 1 :(得分:0)

如果我没记错的话,SSRS 2008 R2中有一个选项可以在添加组时将组小计添加到Tablix。

如果您在事实之后尝试添加它们,则可以创建组页脚行,然后将=SUM(Field!Amount.Value)放入“金额”列,只需硬编码GL帐户中的TOTAL文本柱。由于这仍然在分组范围内完成,因此只有SUM()该组的值。

答案 2 :(得分:0)

我认为,您正在寻找的“总计”将等于数据集中所有金额的总和。我认为这应该有用。

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

答案 3 :(得分:0)

SSRS中的分组肯定不直观。

我设法通过右键点击" Amount"来实现我想要的。字段,然后选择"插入行" - > "外部小组(下方)"。然后我将总和放在新单元格中,并计算出我想要的一切。