问题:如何在SSRS中创建一个动态表达式,以引用列之前的单元格值?
表:该表是按日期使用列分组构建的。
使用的软件:使用Visual Studio 2015报表服务器项目。
示例:查看屏幕截图。
[![在此处输入图像说明] [1]] [1]
答案 0 :(得分:-1)
也许这可以帮到你
DECLARE @TestData TABLE
(
DateColumn DATE ,
ID INT ,
Type NVARCHAR(100) ,
Ammount DECIMAL(18, 2)
);
INSERT INTO @TestData ( DateColumn ,
ID ,
Type ,
Ammount
)
VALUES ( '8/2/2017', 1, N'1_BeginningCash', 1797791 ) ,
( '8/4/2017', 2, N'2_AR', 41526.23 ) ,
( '8/4/2017', 5, N'5_PaymentOther', -19863.21 ) ,
( '8/5/2017', 3, N'3_Vendor_Rebates', 1200 ) ,
( '8/7/2017', 2, N'2_AR', 12163.94 ) ,
( '8/9/2017', 2, N'2_AR', 179236.8 ) ,
( '8/9/2017', 4, N'4_Payment_Supplier', -1066266.32 );
WITH FirstLevel
AS ( SELECT DateColumn ,
ID ,
Type ,
Ammount ,
SUM(Ammount) OVER ( PARTITION BY DateColumn ) AS DateTotal ,
SUM(Ammount) OVER ( ORDER BY DateColumn ,
ID
) AS RunningTotal
FROM @TestData
) ,
SecondLevel
AS ( SELECT FirstLevel.DateColumn ,
FirstLevel.ID ,
FirstLevel.Type ,
FirstLevel.Ammount ,
FirstLevel.DateTotal ,
FirstLevel.RunningTotal ,
LAG(FirstLevel.RunningTotal, 1, 0) OVER ( ORDER BY FirstLevel.DateColumn ,
FirstLevel.ID
) LastRunningTotal
FROM FirstLevel
) ,
ThirdLevel
AS ( SELECT SecondLevel.DateColumn ,
SecondLevel.ID ,
SecondLevel.Type ,
SecondLevel.Ammount ,
SecondLevel.DateTotal
+ FIRST_VALUE(SecondLevel.LastRunningTotal) OVER ( PARTITION BY SecondLevel.DateColumn
ORDER BY SecondLevel.DateColumn ,
SecondLevel.ID
) AS DateTotal ,
FIRST_VALUE(SecondLevel.LastRunningTotal) OVER ( PARTITION BY SecondLevel.DateColumn
ORDER BY SecondLevel.DateColumn ,
SecondLevel.ID
) AS Beginning
FROM SecondLevel
)
SELECT *
FROM ThirdLevel;