简体   繁体   English

具有动态行汇总的SSRS中的动态列?

[英]Dynamic Columns in SSRS with Dynamic Row Summing?

So I've got a pretty simple view that looks like this: 所以我有一个非常简单的视图,看起来像这样:

Location    Month       DelRec      Warehouse_Number    Code    Value
Canada      November    Deliveries  Warehouse1          C       11041.2
Canada      November    Deliveries  Warehouse 2         C       0
Canada      November    Receipts    Warehouse 3         C       0
USA         November    Receipts    Warehouse_10        H       2543.2

Ultimately, what I would like to create is a matrix in SSRS that uses 'Code' as a dynamic column name and grouping by DelRec and Location (expanding the number of columns for each code available for that grouping). 最终,我想在SSRS中创建一个矩阵,该矩阵使用“代码”作为动态列名称,并按DelRec和Location进行分组(扩大可用于该分组的每个代码的列数)。 Easy enough, right? 很容易,对吧? Looks something like this: 看起来像这样:

简单矩阵

Now the next step I've got is to do some conditional summing on these values, which has got me stymied. 现在,我要做的下一步就是对这些值进行一些条件求和,这使我陷入了困境。 In particular, for example, in the below data, for Canada, Deliveries need to be summed up together (Warehouse 1 and 2), and then the total of those two subtracted from Receipts (in this case, just Warehouse 3). 特别是,例如,在以下数据中,对于加拿大,需要将交货汇总在一起(仓库1和2),然后从收据中减去这两个的总数(在本例中为仓库3)。 Ostensibly, this would look something like this: 表面上,这看起来像这样:

with_total

The problem is, I can't figure out how to do conditional summing (ie sum deliveries and subtract them from the sum of receipts), especially when dynamic columns are involved (because we don't know what warehouse numbers might come in future data). 问题是,我无法弄清楚如何进行条件求和(即交货总和并从收据之和中减去它们),尤其是在涉及动态列时(因为我们不知道将来的数据中可能会有哪些仓库号) )。

In addition, I actually need a column that has the Total Deliveries and Total Receipts, which is causing me even further difficulty. 另外,我实际上需要一列包含“总交付量”和“总收据”的列,这使我更加困难。

Anybody have any idea of how to do this? 有人对如何执行此操作有任何想法吗? The result should look something like this: 结果应如下所示:

在此处输入图片说明

I've created a a pastebin with some representative SQL data for insert if anyone would actually like to try this out. 如果有人真的想尝试一下,我已经创建了一个带有一些代表性SQL数据的pastebin ,用于插入。

As I understand essentially "Receipts" are credits and can be treated as a positive amount and "Deliveries" are debits and can be treated as a negative amount. 据我了解,“收据”实质上是贷方,可以视为正数,而“交付”则是借方,可以视为负数。 To get the correct total you could replace the Sum expression in the bottom right of the matrix with 为了获得正确的总数,您可以将矩阵右下角的Sum表达式替换为

=Sum(IIF(Fields!DelRec.Value="Receipts",Fields!Value.Value,-1 * Fields!Value.Value))

To get a total line for deliveries and receipts you need to either right click on Warehouse_Number in the matrix, then click on Add Total then click on After. 要获得交货和收货的总行,您需要右键单击矩阵中的Warehouse_Number,然后单击“添加总计”,然后单击“之后”。

将总计添加到仓库编号

Alteratively you can right click on Warehouse_Number in the Row Groups and add total from there. 或者,您可以右键单击“行组”中的Warehouse_Number,然后从中添加总计。

The matrix should now look like this 矩阵现在应如下所示

在此处输入图片说明

The report should now look like this 该报告现在应如下所示

两者合计

Right clicking on Code in the matrix then "Add Total" -> "After" will add Row Totals as a new column. 右键单击矩阵中的“代码”,然后单击“添加总计”->“之后”,将“行总计”添加为新列。 Note that this will only total "Receipt" or "Deliveries" by Location as the report is grouped Location then DelRec then Warehouse. 请注意,这将仅按位置总计“收货”或“交货”,因为报表被分组为“位置”,“ DelRec”和“仓库”。 You could achieve a Receipt Grand Total through either adding extra rows at the bottom of the matrix, or better in my opinion is another table only grouped by DelRec to calculate the DelRec Grand Totals. 您可以通过在矩阵底部添加额外的行来获得回执总计,或者我认为更好的是另一个仅由DelRec分组以计算DelRec总计的表格。

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

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