I have created an SSRS report.
In this report I have created a dataset called: DataSet1. DataSet1 contains two columns: EntityId (integer) and Name (Varchar). I would like to show a textbox if one of the values in the EntityId column is "27".
So I want to write an expression that does this:
If one of the rows in DataSet1 has a EntityId value of 27, then show the textbox, else hide the textbox.
From reading some other similar questions, I think counting the rows is probably the way to go. So instead it might be something like:
Count the rows where DataSet1.EntityId = 27. If the number of rows is more than 0 then show the SSRS textbox, else hide the textbox.
Any help with the expression would be much appreciated
You can do this easily with a simple expression.
Set the hidden
property of the textbox to
=SUM(IIF(Fields!EntityID.Value = 27,1,0), "DataSet1") = 0
All we are doing here is, starting from the inner expression...
EntityID
= 27, if it does return 1 else return 0."DataSet1"
(your entire dataset)This will return True
if the result is zero (no rows = 27) and therefore hide the textbox
Note: the dataset name must be enclosed in quotes and is case sensitive.
In order to keep the expression simple, I would suggest to add the corresponding flag directly to the DataSet. Following an example:
DECLARE @t TABLE(
EntityID int
,Title nvarchar(10)
)
INSERT INTO @t VALUES
(10, 'Test 1')
,(27, 'Test 2')
,(27, 'Test 3')
,(11, 'Test 4')
,(15, 'Test 5')
,(15, 'Test 6')
,(27, 'Test 7')
SELECT *, COUNT(CASE WHEN EntityID = 27 THEN 1 ELSE NULL END) OVER (ORDER BY (SELECT 1)) AS flag
FROM @t
The column flag
is 0 if no EntityID 27 is found and > 0 if this ID is found, so your expression would be something like if flag > 0 then...
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.