我有一个SSRS报告,该报告使用组变量和执行字段计算的表达式构建。组变量使用查找,算术和逻辑运算在3个数据集之间提供正确的结果。
我需要对Tablix页脚中的变量文本框表达式的结果求和。但是变量不能以这种方式工作,当我在tablix页脚中尝试不同的表达式时,会出现错误。
因此,我进行了对组变量求和的在线搜索,然后使用VB.NET变量和函数进行汇总,然后显示值,从而创建了自定义代码解决方案。但是自定义代码不是很有效。请参阅页面底部的自定义代码。这是我观察到的一些问题
自定义代码问题
Public Dim
,则导出到excel时,总值将更改为0(例如,屏幕上为“ 1,214,284”;导出为excel时为“ 0”。)Public Dim
到Public Shared Dim
,则屏幕上的值相同,它们将导出为excel。 Public Shared Dim
在Visual Studio中似乎很好用。但是,当在报表服务器上执行时,变量会在每次执行报表时累积(即,ExecEvent#1:屏幕上&excel; ExecEvent#2:“ 300value”上屏幕&excel; ExecEvent #3:在屏幕上显示“ 450value”和excel)。 有帮助吗?如何使这些值汇总并导出?如何使自定义代码VB变量正确运行。特别是正确设置和重置服务器上的变量初始化。
自定义代码更正说明
return thisValue
以解决细节变量值带有空白(不打印)的问题,>参考
SSRS Summing Group Variables outside of the group
SSRS code variable resetting on new page
TablixDesign-WithGroupVaraibles
Tablix Footer:组外的组变量表达错误
注意:不允许使用这些表达式
- -错误:表达式只能引用在同一分组范围,包含的分组范围内或在报表中声明的变量内声明的变量。 variabels名称中的字母必须使用正确的转换。
Variables!varExpenditureLifetime.Value
- -错误:变量不能在聚合函数中使用
Sum(Variables!varExpenditureLifetime.Value)
报告代码:
组变量(“ varLWSBegin_LifetimeExpense”)
= Code.addLWSBeginLifetimeExpense(CDbl( IIF(Parameters!boolUseLwsBalance.Value = false, 0, Lookup(Fields!ProjectId.Value, Fields!ProjectId.Value, Fields!LWSBegin_LifetimeExpense.Value, "dsCAPEXAmountsCustomDataUpload")) ))
Tablix组行
Variables!varLWSBegin_LifetimeExpense.Value
Tablix页脚行
Code.getTotalLWSBeginLifetimeExpense()
VB.NET自定义代码
'
' Add group variable values to an external variable declared on the VB Code.
' In Tablix Group Properties variable the value will be the call to the addValue function
' Then on your textbox you call the getValue function:
' Group Var: Code.addValue(Fields!my_field).
' Textbox: Code.getValue()
'
' variable1, addTotalBudget, getTotalBudget
' variable2, addLWSBeginLifetimeExpense, getLWSBeginLifetimeExpense
' variable3, addExpenditureLifetime, getExpenditureLifetime
'
'TEMPLATE
Public totalMyField2 as Integer
Public totalMyFieldName as Integer
Public Function addMyFieldName(ByVal thisMyFieldName AS integer)
totalMyFieldName = totalMyFieldName + thisMyFieldName
End Function
Public Function getMyFieldName()
return totalMyFieldName
End Function
'MyVariables
Public Shared Dim totalTotalBudget as Integer
Public Shared Dim totalLWSBeginLifetimeExpense as Integer
Public Shared Dim totalExpenditureLifetime as Integer
Public Shared Function Initialize()
totalTotalBudget = 0
totalLWSBeginLifetimeExpense = 0
totalExpenditureLifetime = 0
End Function
'Functions
Public Function addTotalBudget(ByVal thisValue AS Integer )
totalTotalBudget = totalTotalBudget + thisValue
return thisValue
End Function
Public Function addLWSBeginLifetimeExpense(ByVal thisValue AS Integer )
totalLWSBeginLifetimeExpense = totalLWSBeginLifetimeExpense + thisValue
return thisValue
End Function
Public Function addExpenditureLifetime(ByVal thisValue AS Integer )
totalExpenditureLifetime = totalExpenditureLifetime + thisValue
return thisValue
End Function
Public Function getTotalBudget()
return totalTotalBudget
' Dim myval as Integer = totalTotalBudget
' totalTotalBudget = 0
' return myval
End Function
Public Function getTotalLWSBeginLifetimeExpense()
return totalLWSBeginLifetimeExpense
' Dim myval as Integer = totalLWSBeginLifetimeExpense
' totalLWSBeginLifetimeExpense = 0
' return myval
End Function
Public Function getTotalExpenditureLifetime()
return totalExpenditureLifetime
' Dim myval as Integer = totalExpenditureLifetime
' totalExpenditureLifetime = 0
' return myval
End Function
'<END>
我有一个SSRS报告,该报告使用组变量和执行字段计算的表达式构建。组变量使用查找,算术和逻辑在3个数据集之间提供正确的结果...
能够像尝试使用变量一样简单的方法是使用Report Variables而不是组变量。如果使用报告变量,则可以从任何范围访问它。