My visibility condition in SSRS caused "[BC30516] Overload resolution failed because no accessible 'IIf' accepts this number of arguments." error - reporting-services

I am using the following expression for a row visibility rule:
=IIF(Sum(Fields!bt_actual_usage.Value) > 0
AND (Count(Fields!bt_actual_usage.Value) < Parameters!Consecutive.Value)), true, false)
When I try saving the report I get the following error message:
"The Visibility.Hidden expression for the tablix ‘Tablix1’ contains an error: [BC30516] Overload resolution failed because no accessible 'IIf' accepts this number of arguments."
I think I only have three arguments, as I should. What am I doing wrong?
I have also attempted to replace the IIF with something like this:
=IIF(Sum(Fields!bt_actual_usage.Value) > 0, true, false)
AND IIF((Count(Fields!bt_actual_usage.Value) < Parameters!Consecutive.Value), true, false)
I got the same error.

There's an extra closing parethesis at the end of the parameter value that causing the IIF to close with only one argument.
=IIF(Sum(Fields!bt_actual_usage.Value) > 0
AND (Count(Fields!bt_actual_usage.Value) < Parameters!Consecutive.Value)), true, false)
Your working answer removed the opening parenthesis before the count and the TWO after the parameter.
Removing just one would have worked. This is why I try to use as few parenthesis as possible, but as many as needed.
=IIF(Sum(Fields!bt_actual_usage.Value) > 0
AND (Count(Fields!bt_actual_usage.Value) < Parameters!Consecutive.Value), true, false)

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*")

SSRS Reporting Syntax

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.

SSRS how to have two different condition in Action Property

I am working in a SSRS that needs to link a report based on the value in a textbox.
I have tried:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",Nothing)
Which works fine, but when I try to add another condition like this:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",Nothing) OR
IIf(Fields!Factors.Value = "TOTAL","Disposition",Nothing)
Then it does not link any report. How do I do this right?
What you are trying does not work correctly as the IIF statements are not nested and what it is doing is:
IIF(this, true part, false part) OR IIF(this, true part, false part)
So when Fields!Factors.Value = "Touched Leads" the expression evalutes to SCPL OR Nothing which isn't valid.
Alternatively you could use SWITCH which has a nicer syntax, the final True statement is your catch all
=SWITCH(
Fields!Factors.Value = "Touched Leads", "SCPL",
Fields!Factors.Value = "TOTAL", "Disposition",
True, Nothing
)
I think that the expression you need will look like this:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",
IIf(Fields!Factors.Value = "TOTAL","Disposition",Nothing))
This checks the first condition ("Touched Leads"), if that is true, link the SCPL report, otherwise check the "TOTAL" condition. If that one is false, return Nothing.

How can I hide specific duplicate rows in SSRS 2005?

Here's my problem: I have some some duplicate rows (rows with the same ID). What I want is to hide rows based on a specific's column value. The mentioned column is obviously not the ID column (it's the Description column).
I tried this on the Row Visibility (Expression):
=IIF (Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value)
AND
ReportItems!Description.Value <> "Incident Status Change to Work In Progress from Open", true, false)
So, I want to exclude the rows in which Description is not equal to 'Incident Status Change to Work In Progress from Open'.
The message that I get is:
The Hidden expression for the table 'table 1' contains an error:
Object variable or With block variable not set.
Any ideas on this?
Thanks in advance
I think you are probably getting that error because there are one or more rows in your query result that have a NULL value in the Description field.
You could test this theory by simplifying your expression to this:
=IIF(Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value), true, false)
just to see if you can run the report without error.
If that works, then you need to add a test for a NULL value as part of the larger condition test, to get back to the logic you intended.
Try this:
=IIF(Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value) AND IsNothing(Fields!Description.Value) = false AND Fields!Description.Value <> "Incident Status Change to Work In Progress from Open", true, false)
This should avoid the error by preventing the evaluation of the last part of the condition, when the Description has a NULL value.
I think you're on the right track just using ReportItems instead of Fields!
=IIF(Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value) AND Fields!Description.Value <> "Incident Status Change to Work In Progress from Open", true, false)
SSRS can be wonky sometimes. Try parenthesizing:
=IIF(((Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value)) AND (IsNothing(Fields!Description.Value) = false) AND (Fields!Description.Value <> "Incident Status Change to Work In Progress from Open")), true, false)