简体   繁体   English

创建带有计算行的 SSRS 报告

[英]Create a SSRS Report with calculated row

I have created a report which shows the following information:我创建了一个报告,其中显示了以下信息: 在此处输入图片说明

but i need to add a new row with a calculated field every time the "Turno" changes and another row at the end of the table, something like this:但我需要在每次“Turno”更改时添加一个带有计算字段的新行,并在表末尾添加另一行,如下所示:

在此处输入图片说明

This is my very first time creating a report like this so any help will be appreciated, Thanks.这是我第一次创建这样的报告,所以任何帮助将不胜感激,谢谢。

Edit.编辑。 the suggested answer: Adding subtotals to SSRS report tablix doesn't work for me.建议的答案: 向 SSRS 报告 tablix 添加小计对我不起作用。 This answer groups all the "NOCHE", then all the "MAÑANA" and then all the "TARDE" but i need to group when "Turno" changes in the next row, not all the record with the same Turno.这个答案将所有“NOCHE”分组,然后是所有“MAÑANA”,然后是所有“TARDE”,但我需要在下一行中的“Turno”更改时分组,而不是所有具有相同Turno的记录。 Thx in advance and sorry for my english.提前感谢并为我的英语感到抱歉。

There may a way to do this directly in SSRS but I would try to do this in your dataset query if possible.可能有一种方法可以直接在 SSRS 中执行此操作,但如果可能,我会尝试在您的数据集查询中执行此操作。

The following query recreates your dataset and then adds an extra column GroupByID which you can then use in your report to easily group the data.以下查询重新创建您的数据集,然后添加一个额外的列GroupByID ,然后您可以在报告中使用它来轻松地对数据进行分组。

The first part of the query is just to produce some data, you only need the main SELECT part and you can swap @t for the name of your table.查询的第一部分只是生成一些数据,您只需要主要的 SELECT 部分,您可以将 @t 交换为您的表名。

DECLARE @t TABLE(Relevo char(1), ID int IDENTITY(1,1), Turno varchar(10), TT float)

INSERT INTO @t(Relevo, Turno, TT) VALUES
('A', 'NOCHE', 0.085),('A', 'NOCHE', 0.1),('A', 'NOCHE', 0.099),('A', 'NOCHE', 0.055),('A', 'NOCHE', 0.07),
('A', 'NOCHE', 0.076),('A', 'NOCHE', 0.102),('A', 'MANANA', 0.06),('A', 'MANANA', 0.065),('A', 'MANANA', 0.064),
('A', 'MANANA', 0.126),('A', 'MANANA', 0.136),('A', 'MANANA', 0.107),('A', 'NOCHE', 0.059),('A', 'NOCHE', 0.121),
('A', 'NOCHE', 0.063),('A', 'NOCHE', 0.055),('A', 'NOCHE', 0.056),('A', 'NOCHE', 0.085)

-- Change @t below for the name of your table
SELECT z.Relevo, z.ID, z.Turno, z.TT, MIN(z.GroupByID) AS GroupByID
    FROM(
        SELECT
            a.*, b.id  AS GroupByID
        FROM @t a 
            LEFT JOIN 
            (SELECT * FROM (
                SELECT 
                    * 
                    ,LastEntry = IIF(LEAD(Turno,1,'') OVER(ORDER BY ID) = Turno, 0,1)
                FROM @t
                ) x WHERE x.LastEntry = 1
                ) b
            ON a.Relevo = b.Relevo and a.Turno = b.Turno and a.id <=b.ID
    ) z
    GROUP BY z.Relevo, z.ID, z.Turno, z.TT
    ORDER BY ID

This gives the following output这给出了以下输出

在此处输入图片说明

Now all you have to do in SSRS is add a parent row group, grouped by GroupByID and add the expression you required (eg =AVG(Fields!TT.Value) ).现在您在 SSRS 中要做的就是添加一个父行组,按GroupByID分组并添加您需要的表达式(例如=AVG(Fields!TT.Value) )。

The report design will look like this...报告设计将如下所示...

在此处输入图片说明

NOTE: I am showing the first column for clarity but you can delete this.注意:为清楚起见,我显示了第一列,但您可以删除它。

The final output looks like this.最终输出看起来像这样。

在此处输入图片说明

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

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