简体   繁体   English

如何总结 rdlc 报告中每组中列的最后一行值?

[英]How can i sum up the last row value of a column in each group in a rdlc report?

I want to add only the last row value of any column of each group in a rdlc report, so, iam having an rdlc group report, which has a balance column, so what i want is to add the last balance value of each group in the report,here is how my table looks like '我只想在 rdlc 报告中添加每个组的任何列的最后一行值,所以,我有一个 rdlc 组报告,它有一个 balance 列,所以我想要的是添加每个组的最后一个 balance 值报告,这是我的桌子的样子'

Customer   Balance
  Mark       1500
  Mark       2500
-----------------------
  Steve     4500
  Steve     5600
-----------------------
 Alex      10000
 Alex      24000

'.and i want to add the last balance value of each Customer, which is 2500+5600+24000, here is the rdlc expression i have tried before and which did not work: '.并且我想添加每个客户的最后一个余额值,即 2500+5600+24000,这是我之前尝试过但不起作用的 rdlc 表达式:

'=SUM(LAST(fields!balance.value),"mygroup")'

I would be glad if someone provides me the solution of fixing this problem.如果有人为我提供解决此问题的解决方案,我会很高兴。

As you may have realised, you can't use FIRST, LAST etc in an outer aggregate but there is away to get around it.正如您可能已经意识到的那样,您不能在外部聚合中使用 FIRST、LAST 等,但是可以绕过它。

First I replicated your data, but I also added a sort column.首先,我复制了您的数据,但还添加了一个排序列。 I assume you will have a column to sort on already (an invoice number of date etc).我假设您已经有一个列可以排序(日期的发票编号等)。

The trick is to sum only if the sort value is the same as the maximum sort value for the group, it will be clearer with an example.诀窍是仅当排序值与组的最大排序值相同时才求和,举个例子会更清楚。

Here's the sample data I produced.这是我制作的示例数据。

DECLARE @t TABLE (Customer varchar(50), sort int, Amount int)
  INSERT INTO @t VALUES
    ('Mark', 1, 1500),
    ('Mark', 2, 2500),
    ('Steve', 1, 4500),
    ('Steve', 2, 5600),
    ('Alex', 1, 10000),
    ('Alex', 2, 24000)

  SELECT * FROM @t 

Next I created a new report, added the above query as a dataset query and added simple table to the report.接下来,我创建了一个新报表,将上述查询添加为数据集查询,并将简单表添加到报表中。

I added a Row Group to group by Customer and sorted that group by sort .我添加了一个 Row Group 以按Customer分组,并按 sort 对该组进行sort

I then added a final row outside the groups and set the expression to give the results you require.然后,我在组外添加了最后一行,并设置表达式以提供您需要的结果。

Here's the simple report layout.这是简单的报告布局。

在此处输入图像描述

Here's the expression I used.这是我使用的表达方式。

=Sum(
    IIF(
        Fields!sort.Value = MAX(Fields!sort.Value, "Customer"),
        Fields!Amount.Value,
        0
        )
    )

Note: The "Customer" string refers to the Row Group name (highlighted in the image), not the dataset column.注意: "Customer"字符串是指行组名称(在图像中突出显示),而不是数据集列。

Here is the final output这是最终的 output

在此处输入图像描述

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

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