[英]Assigning NO DATA instead showing blank cells in ssrs 2008 - based on row visibility expression
I have a problem in SSRS 2008 described as below: 我在SSRS 2008中遇到问题,如下所述:
I have a matrix which is connected to a query, lets say Select * from Table
. 我有一个连接到查询的矩阵,可以说
Select * from Table
。 It is returning, lets say 50 rows of data. 它正在返回,可以说有50行数据。 In my matrix, there is only one row.
在我的矩阵中,只有一行。 Lets say:
可以说:
id name grade
[id] [name] sum[grade]
The matrix is grouped by 'id' and 'name' in Row Group. 矩阵在行组中按“ id”和“ name”分组。 There is a row visibility expression for this row like
=IIF(sum(Fields!grade.Value)>95,false,true)
. 该行有一个行可见性表达式,例如
=IIF(sum(Fields!grade.Value)>95,false,true)
。 Assuming that for this situation, this table shows no data, all the returned 50 rows of data has a grade lower than 95 in total. 假定在这种情况下,该表未显示任何数据,则所有返回的50行数据的总分低于95。 Therefore, I see only the columns without any information on the screen like:
因此,我在屏幕上只能看到没有任何信息的列,例如:
id name grade
What I want is to write "No Data" instead' like: 我要写的是“无数据”,例如:
id name grade
No Data
Normally, when there is no data returning from the query, I would do it by going Tablix Properties and assign "No Data" to the NoRowsMessage property. 通常,当查询没有返回数据时,我可以通过Tablix属性并将NoData指定给NoRowsMessage属性来实现。 This is not working for this situation, and I could not figure out how I can count the displayed row number in a matrix.
这不适用于这种情况,并且我无法弄清楚如何计算矩阵中显示的行数。 Any help would be appreciated.
任何帮助,将不胜感激。
You can do this by adding a row add the end of the tablix and outside the Row Group. 您可以通过添加一行,将Tablix的末尾添加到“行组”之外来执行此操作。
Once the row is created type No Data
in the first cell of the row. 创建该行后,在该行的第一个单元格中键入
No Data
。
Select the No Data
row and go to Row Visibility
property and set this expression: 选择“
No Data
行,然后转到“ Row Visibility
属性并设置以下表达式:
=IIF(
Sum(IIF(Fields!Grade.Value>95,1,0))>0,True,False
)
When all rows have Grade 95 or less the No Data row will be shown but the data rows will be hidden. 当所有行的等级均为95或更低时,将显示“无数据”行,但数据行将被隐藏。
UPDATE Update based on OP's feedback. UPDATE根据OP的反馈进行更新。 Grade column is an sum expression.
成绩栏是一个求和表达式。
In that case it is useful use the LookupSet
function to get the grades by ID. 在这种情况下,使用
LookupSet
函数通过ID获取成绩很有用。 They will be returned in an array data type so we require custom code to sum the ID grades. 它们将以数组数据类型返回,因此我们需要自定义代码来汇总ID等级。
Go to Report
Menu / Report Properties...
, select the Code
tab and paste the following code. 转到
Report
菜单/ Report Properties...
,选择“ Code
选项卡并粘贴以下代码。
Dim HiddenFlag as Integer = 0
Function CalculateHiddenFlag(ByVal items As Object()) As Integer
If items Is Nothing Then
Return HiddenFlag
End If
Dim sumItems As Decimal = New Decimal()
sumItems = 0
For Each item As Object In items
sumItems += Convert.ToDecimal(item)
Next
If (sumItems > 95 and HiddenFlag=0) Then
HiddenFlag = 1
End If
Return 0
End Function
Function GetHiddenFlag() As Integer
Return HiddenFlag
End Function
Now modify the [Sum(Grade)]
cell expression an use this one: 现在修改
[Sum(Grade)]
单元格表达式,并使用此表达式:
=Sum(Fields!Grade.Value)+
Code.CalculateHiddenFlag(
LookupSet(Fields!ID.Value,Fields!ID.Value,Fields!Grade.Value,"DataSet15"))
Replace
DataSetName
by the actual name of yours.用您的实际名称替换
DataSetName
。
Your matrix should look like this: 您的矩阵应如下所示:
For the No Data
row visibility property use the following expression: 对于“
No Data
行可见性属性,使用以下表达式:
=IIF(Code.GetHiddenFlag()=1,True,False)
It will return this when at least one row has Grade > 95. 当至少一行的成绩> 95时,它将返回此值。
And this when there is no rows which Grade is greater than 95. 而当没有行的成绩大于95时。
Let me know if this helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.