SSRS Reporting Syntax - reporting-services

Using the following filter for a SSRS report.
Expression:
=If((Parameters!GroupA.Value() In Fields!Related_GroupA.Value) Or (Parameters!GroupB.Value() In Fields!Related_GroupB.Value) Or (Parameters!GroupA.Value() In Fields!GroupA.Value) Or (Parameters!GroupB.Value() In Fields!GroupB.Value))
Operator:
=
Value:
True
Believe the syntax for the "If statement" and use of "in" and "Or" may be incorrect. Need to return the results if the value selected in the report parameter, appears in one of two places. (e.g. if Parameters!GroupA is in Fields!Related_GroupA or in Fields!GroupA)
Current Error:
'If' operator requires either two or three operands.

'If' operator requires either two or three operands.
You have the "if" part in your statement but you don't specify what to do if it returns true or false. Also, use "iif" instead of "if."
=iif(
(Parameters!GroupA.Value In Fields!Related_GroupA.Value) Or
(Parameters!GroupB.Value In Fields!Related_GroupB.Value) Or
(Parameters!GroupA.Value In Fields!GroupA.Value) Or
(Parameters!GroupB.Value In Fields!GroupB.Value), <Value if true>, <Value if false>)
If you only want to return true or false then you don't need to use the iif operator because the "=" operator returns a boolean value (True/False).
If this is the case then you can simply use:
=(Parameters!GroupA.Value = Fields!Related_GroupA.Value) Or
(Parameters!GroupB.Value = Fields!Related_GroupB.Value) Or
(Parameters!GroupA.Value = Fields!GroupA.Value) Or
(Parameters!GroupB.Value = Fields!GroupB.Value)
Note that I changed "In" to "=" because there isn't an IN operator you can use in the ssrs expressions but there are a few workarounds. See here and here.

Related

Index was outside the bounds of the array in SSRS

I have two parameters , let's say P1 and P2. The sample expression I used for P2 is
IIF(P1.Label="string", "null" ,Split(P1.Label," ").GetValue(0))
When the condition is false, the split expression is working fine. But if the condition is true, I'm getting 'Index was outside the bounds of the array' error. If the condition is true, I need to pass the value "null" as varchar type.
Can someone please advice on this?
The problem with the IIF function is that it is a function not a language construct. This means that it evaluates both parameters before passing the parameters to the function. Consequently, if you are trying to do a Split on a parameter that can't be split, you will still get the 'Index was outside the bounds of the array' error, even when it looks like that code shouldn't be executed due to boolean condition of the IIF statement.
The best way to solve this is to create a safe string splitter function in custom code where you can use real language constructs. Also, check that the string is splittable by checking it contains a space instead of checking for a special string:
Public Function SafeSplit(ByVal SplitThis As String) As String
If InStr(SplitThis, " ") Then
Return Split(SplitThis, " ")(0)
End If
Return "null"
End Function
and then use this in your report for the Value expression instead of IIF:
=Code.SafeSplit(Parameters!P1.Label)

IIF statement with null value and multiple condition

I'm getting a problem with one of my expression in my report. It always gives me #Error and I think I know why but don't know how to set my expression.
Here's my expression :
=IIF(Fields!CMMTTEXT.Value.Contains("*Return*") AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
The Fields CMMTTEXT can be null sometimes and I'm getting an error on all of my rows except the one that has data in the CMMTTEXT field.
So I need a isnothing but I've tried couple ways of doing it but doens't seem to work
=IIF(IsNothing(Fields!CMMTTEXT.Value.Contains("*Return*")) AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
also this that I've seen on this forum :
=IIF(IsNothing(Fields!CMMTTEXT.Value) OR Fields!CMMTTEXT.Value.Contains("*Return*") AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
I have no idea at this point.
Thanks for the help!
The Contains function doesn't work with NULL values. Once it throws an error, the IsNothing function subsequently can't evaluate the results. Separating these out using the OR operator also doesn't work because it tries to evaluate both conditions even when the first one was true.
One way to work around this is to first check for NULL values and replace them with an empty string. Then use the Contains function on the results of this expression:
=IF(IsNothing(Fields!CMMTTEXT.Value), "", Fields!CMMTTEXT.Value).Contains("*Return*")

#ERROR Help, SSRS Report Builder, IIF w/ LOOKUPSET

I'm trying to compare 2 rows of data in the form of %'s. I generate and it "#Error".
=IIF(Fields!Grade.Value = "ONGRADE" > LookupSet(Fields!Grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE", "Previous3Week"), "UP" ,"DOWN")
There are two DataSets.
You are using IIF incorrectly. IIF just looks at a comparison and returns the first value if TRUE and the second value if false.
=IIF(1 = 2, True, False)
Which reads as
If 1 = 2 then return TRUE else return False
You are also using LookUpSet incorrectly. The first LookUpSet argument is your current dataset field that you want to compare, the second argument is the field from the first that you want to compare to - since your using the same dataset, they might be the same. The third LookUpSet argument is the field that you want to return (you know the ONGRADE field, what value do you want back?).
Your expression reads, if Grade = ONGRADE > LookupSet(blah blah) ...
What is the value field that you want to compare? Assuming it's Fields!GRADE_VALUE.Value, your IIF might be like
=IIF(Fields!Grade.Value = "ONGRADE",
IIF(Fields!GRADE_VALUE.Value >
LookupSet(Fields!Grade.Value, Fields!grade.Value, Fields!GRADE_VALUE.Value", "Previous3Week"),
"UP" ,
"DOWN"),
"Not ONGRADE")
If you want all GRADE types (not just ONGRADE) compared, it would be simpler:
=IIF(GRADE_VALUE > LookupSet(Fields!Grade.Value,
Fields!grade.Value,
Fields!GRADE_VALUE.Value,
"Previous3Week")
, "UP"
,"DOWN")

SUM IIF Expression returning an error

I have a simple expression that should work,but it keeps returning an error.
Please keep in mind, the Parameter is a Multi elect Parameter.
=SUM(IIF(Fields!Month.Value = Month(Today()) AND Fields!Year.Value = Year(Today()) AND Fields!Warehouse.Value = Parameters!warehouse.Value, Fields!Budget.Value, 0), "Budgets")
Since the parameter is multi-value, the values are passed as an array. One way to handle this is by combining the values into a comma-separated string.
So you would replace Fields!Warehouse.Value = Parameters!warehouse.Value with:
InStr(Join(Parameters!warehouse.Value, ","), Fields!Warehouse.Value) > 0

Checking for null and a value in SSRS

I want to check a value in an SSRS report to make sure that it isn't null, first, and then that it equals a particular value. My expression is as follows:
=iif(IsNothing(First(Fields!RecordStatusFlagId.Value, "DataSource")),"",(First(Fields!RecordStatusFlagId.Value, "DataSource") = 1,"","DELETED"))
So if RecordStatusFlagID.Value is not null and it doesn't equal 1 write "DELETED". Otherwise write "".
However, this gives me the error:
Error 75 [rsCompilerErrorInExpression] The Value expression for the textrun ‘textbox21.Paragraphs[0].TextRuns[0]’ contains an error: [BC30198] ')' expected. C:\Reports\MyReport.rdl 0 0
which doesn't make sense since I've verified that all of my parentheses are closed and matched.
Is it even possible to use an expression as the second term in the IsNothing operator?
I needed to add an iif to the second portion of the IsNothing expression
=iif(IsNothing(First(Fields!RecordStatusFlagId.Value, "DataSource")),"",iif(First(Fields!RecordStatusFlagId.Value, "DataSource") = 1,"","DELETED"))
I think you could simplify that into a single iif() statement:
=iif(
First(Fields!RecordStatusFlagId.Value, "DataSource") <> 1
And First(Fields!RecordStatusFlagId.Value, "DataSource") Is Not Nothing
, "DELETED"
, ""
)