简体   繁体   English

SSRS与小组总结

[英]SSRS Summing with Groups

I have created an SSRS report that will display multiple Orders and the Items that are in the Order. 我创建了一个SSRS报告,该报告将显示多个订单和订单中的项目。 It looks something similar to: 它看起来类似于:

Order #  |  Order Amount   |   Item   |   Item Cost   |   Item Qty
------------------------------------------------------------------
1000              $5,000
                               Foo           $1,000              2
                               Bar           $3,000              1 
1001              $6,000       Foo           $1,000              6

It will list the Order on the first row and the details of the order on the rows underneath it. 它将在第一行列出订单,并在其下一行列出订单的详细信息。

I have my report set to group on my Order Id. 我已将报告设置为按订单ID分组。 The first row would be a header row for the group, and then the order item rows are basically details rows in the group. 第一行将是该组的标题行,然后订单项行基本上是该组中的明细行。

The query I have to return this data is like this: 我必须返回此数据的查询是这样的:

SELECT * FROM Orders LEFT JOIN OrderItems ON Order_Id = Order_Id

The data returned from the query will look like: 查询返回的数据如下所示:

OrderId      | OrderAmount      | ItemName     | ItemCost     | ItemQuantity
----------------------------------------------------------------------------
1000           5000               Foo            1000           2  
1000           5000               Bar            2000           1
1001           6000               Foo            1000           6

In the report I do a group on the OrderId - the header row displays Order Amount. 在报告中,我在OrderId上进行分组-标题行显示Order Amount。 The details rows display the item name, cost and quantity. 明细行显示物料名称,成本和数量。 Everything works great until I want to put a total for all of the orders on the bottom of the report. 一切工作都很好,直到我想将所有订单的总计都放在报告底部。 If an order has more than one item then it will count the order amount multiple times (which is expected since the data is there multiple times). 如果订单中有多个项目,则它将对订单金额进行多次计数(这是预期的,因为数据在那里存在多次)。

Is there a better way that I could design the report or the query? 有没有更好的方法可以设计报告或查询?

In your table footer, use the ItemCost * ItemQty and SUM on that. 在表格页脚中,使用ItemCost * ItemQty和SUM。 Use this: 用这个:

=sum(Fields!itemcost.Value * Fields!ItemQty.Value) = sum(字段!itemcost.Value *字段!ItemQty.Value)

I set up a small example with your data and this works, with what you have displayed. 我为您的数据建立了一个小示例,并且对您显示的内容也有效。

Add a footer row to your datagrid and add a sum of the DATASET OrderAmount column, not of the FIELDS!OrderAmount . 在数据网格中添加页脚行,并添加DATASET OrderAmount列的总和,而不是FIELDS!OrderAmount That should do it. 那应该做。

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

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