Removing duplicate rows with an expression for the Visibility property - reporting-services

I'm using Microsoft Visual Studio and I'm trying to stop duplicate rows. The row in question is grouped. Under field properties there is an area called Visibility. For the Hidden value I am entering
Fields!fp_id = Previous(Fields!fp_id, True, False)
I get the message that it is not a valid Boolean value.

The previous Function has this signature:
Previous(expression, scope)
Also, you're calling the field itself instead of its .Value.
Finally, SSRS usually doesn't like comparison statements in places where it wants a single final value.
Try this:
=Iif(Fields!fp_id.Value = Previous(Fields!fp_id.Value), True, False)
The Iif function has this signature:
Iif(TestExpression, TrueValue, FalseValue)

Related

Conditional hiding of a textbox using an expression and parameter value

I am using visual studio 2008 to write a reporting services report.
I am trying to conditionally hide a textbox/label on my rss report. I have an integer input parameter the user in the form marks yes or no, but the parameter is assigned either a 0 or a 1 depending on the answer.
My current expression is:
=iif(Parameters!#onetime.value = 0, True, False)
I get error bc30455, argument not specified for parameter 'TruePart'... blah blah
It looks like you may be declaring the parameter incorrectly.
Your parameter should look like Parameters!onetime.Value without the # sign.
Additionally, for the full statement, I'm assuming this is being used in the visibility settings. For that property, False means the textbox will be visible and True will hide the textbox. The expression you'll need should look like this:
=IIF(Parameters!onetime.Value = 0, True, False)
This expression will hide the textbox if the onetime parameter is set to 0.
You seem to be using the parameter incorrectly.
If your parameter is named onetime, the expression should be
=IIf(Parameters!onetime.Value = 0, True, False)
When using the expression editor, you can insert the correct syntax by selecting your parameter from the list of parameters.
Using this expression in the Visible property, the textbox will be visible if and only if the onetime parameter is set 0.

SSRS tablix visibility

I have a multi-parameter report in SSRS where I want to display or hide a report depending on the parameter selection. If the user selects only one facility from a multi-value facility parameter then I want a second report to display along with the main report(it would be a separate tab). If multiple facilities are chosen then I only want the main report to display.
I've been playing with the visibility expressions on the second report but I can't seem to get it to work.
I've tried:
=IFF(Parameters!entity.IsMultiValue, "True", "False")
but that returns an error "The hidden expression used in tablix returned a data type that is not valid.
I've also tried:
=IIF(Parameters!entity.Count = 1), "False", "True")
But I get the same error. I'm using SSRS 2016.
False and True are not strings but constants.
Change it to:
=IIF(Parameters!entity.IsMultiValue="Your value", True, False)
And the second one to:
=IIF(Parameters!entity.Count = 1, False, True)
Good luck.
True and False are not strings, they are booleans. The Visibility property looks for a boolean, but in the expressions you gave (assuming your syntax was correct when testing it), you are passing strings since you have them enclosed in double quotes. Remove the double quotes and that will clear that error.
You also don't need to use IIf here -- you can simply use the first argument of the IIf, since that by itself will evaluate to True or False. I doubt there is any appreciable performance difference, but just a small thing to note.

SSRS: How to filter query with custom function

Using VS 2015 and SSRS version 14.0.608.142
I have a function in the code section of my report properties similar to below and I'm trying to use it to filter out values in my dataset but it's not returning any values or giving any errors. The value inside the function would be changed at run time by another application so the value inside it right now is just a placeholder.
Function FilterBy() As String
FilterBy = "'REMIT'"
End Function
I have the function being used as a default value in a parameter and the parameter is in the where clause of my dataset to filter out the necessary values.
So, inside parameter default value:
=code.FilterBy
Dataset query:
SELECT Blah
FROM dbo.Table
WHERE ID = #parameter;
So, I'm noticing in your function that you're setting a variable but not returning it. If you're trying to set a Variable in the report properties, they can't be modified. Those things are static. You can, however, declare a variable in your code and use set and gets to retrieve them.
dim FilterBy = "REMIT"
Function getFilter() As String
return FilterBy
End Function
Function setFilter(input as String)
FilterBy = input
End Function
Therefore your parameter default value would be:
=Code.getFilter()
Also notice that I'm not adding single quotes to REMIT. When you pass a parameter in your query you do not need to add single quotes to it, it will be added by SSRS. Unless the value is 'REMIT' in your database, then by all means, carry on.

SSRS 2005: how to write an IIF statement to check whether values are in a parameter list

In SSRS 2005, I'm trying to set up an expression to return true or false, according to whether the value of one of the ReportItems is in a list of (possibly multiple) values selected by the user from a list when the report is run.
Here's the expression so far:
=iif(Trim(ReportItems!Category_2.Value) = Trim(Parameters!Category.Value(0)), False, True)
You can see that True and False in the expression are reversed - this is because it's to control the 'Hidden' property of the row, and I want to NOT hide rows where the value is in the list.
The expression works fine when choosing single values for the parameter, but for multiple values, it only displays the results for the very first.
Hope you can help.
Try using
=iif(Trim(ReportItems!Category_2.Value) = Trim(Parameters!Category.Value), False, True)
Many thanks for your help. These multiple values were really bugging me, and I never managed to get Trim to work properly, so I ended up using the following two-stage solution, instead:
(1) In the SQL 'SELECT' statement, I defined a new value called 'InCategory', assigning it a value of 1 or 0 according to whether the Category was one of the inputted Categories or not:
CASE WHEN Category IN (#Category) THEN 1 ELSE 0 END AS 'InCategory',
(2) Then in SSRS, my expression for the 'Hidden' in the report became simple, hiding the row if the sum of 'InCategory' for that row was 0:
=iif((Sum(Fields!InCategory.Value) = 0), True, False)
Thank you again for your help - I much appreciate it, and will use this site again.

Code not running when Field is NULL - SSRS 2005

I have a textbox in my SSRS 2005 report. The expresssion for this textbox is:
=IIF(IsDBNull(Fields!fOrgID), Code.SetMyVar("null"), Code.SetMyVar(Fields!fOrgID.Value))
I have also tried IsNothing(Fields!fOrgID) and a few other variations of checking for nulls.
I have modified the SetMyVar function for testing and it now looks like this:
Public Function SetMyVar (var as String)
MsgBox(var, VbOKCancel, "Test1")
If var Is Nothing Then
Return "NOTHING"
Else
MyVar = var
Return var
End If
End Function
I also have the public variable MyVar:
Public Shared Dim MyVar as String
When my database query returns data, this correctly evaluates, a messagebox is displayed with the value, the textbox gets set with the value, and the world is generally a happier place.
When my database query does not return a value though, I get the error:
The query returned no rows for the data set. The expression therefore
evaluates to null.
and the SetMyVar function never appears to be ran (you never get the messagebox popup). As expected, my emotions range from anger, sadness, and bitter hatred of SSRS.
I read something about SSRS evaluating both sides of an IF statement, so perhaps that is why I get the error (likely then on Code.SetMyVar(Fields!fOrgID.Value))... not sure how I get around that though.
Thoughts? Suggestions? Words of comfort?
From the sound of things, it seems likely that the issue is that SSRS is having a problem displaying zero records. I'd recommend one of the following:
1) Use a control that handles zero records appropriately (Tables do. I think Lists do as well).
2) Modify your query to return a single record with blank values if it would otherwise return zero records.
An answer to the original question:
=IIF(IsNothing(Fields!fOrgID),
Code.SetMyVar("null"),
Code.SetMyVar(IIF(IsNothing(Fields!fOrgID),"Foo",Fields!fOrgID.Value)))
The error was from both sides of IIF being evaluated. The extra IIF in the statement above will avoid Code.SetMyVar from ever being called with a null value.
I believe you're right about about Iif always evaluating both of its value arguments (at least, it does in Visual Basic). I'm not sure why you're getting this precise error (unless strings can't be assigned a value of DBNull?), but you almost certainly want to attack this problem with a different method.
The reason for this is that your current code will likely always call both set methods regardless of the conditional value.
Formula that worked for my SSRS 2008 reports.
=IIf(String.IsNullOrEmpty(Fields!NullableFieldwithPossibleBlankStrings.Value),"Yes","No")
I tried this too (also tried a version with IsNothing)...
=Code.SetField(IsDBNull(Fields!fOrgID))
And changed the function to be one that accepts a boolean. I figure this above function would always return a true or false, but in the event of a NULL, I again get "The query returned no rows for the data set. The expression therefore evaluates to null.".
I need to pass back to my code if the field is null or not (as this will let me know if the datasource is null or not).
Let me know if you can think of a better way because I cannot.