Checking for null and a value in SSRS - reporting-services

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

Related

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.

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

SpagoBI OLAP report passing optional parameter

Helo. Today is my another fight day with OLAP raport with optional parameter. I have problem with MDX query. I wrote it like this:
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF(ISEMPTY([CUSTOMER].[${param}]) //CHECKING IF PARAMETER IS EMPTY
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[${param}]}
)
}ON ROWS
from [TRANSACTIONS]
${param} is my optional parameter for [CUSTOMER].[COUNTRY]. I unchecked "required" check button for my parameter, so OLAP should have all [VALUE] after executing it without parameter. And there is a problem, because after launching my OLAP raport parameter probably wants to be filled with something. It gives me an error.
Profile attribute 'param' not existing.
But I dont want to fill it with profile attribute. I have created list of values, and analytical driver for my parameter, which I use to pass possible values to my list box string parameter - ${param}.
Is there possibility to have OLAP report with optional parameter? Any BI master here?
I would be greatfull for any help.
Update: I have done something like this, I think this syntax is right, (I was checking SpagoBI examples)
WITH MEMBER [CUSTOMER].[SELECTED] AS ' Parameter("param") ' , SOLVE_ORDER = 2
MEMBER [CUSTOMER].[LEN] AS ' LEN(Parameter("param")) ', SOLVE_ORDER = 1
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF([CUSTOMER].[LEN]=0
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[CUSTOMER].[SELECTED]}
)
}ON ROWS
from [TRANSACTIONS]
But now I have same error for both possibilities (set/unset) parameter
javax.servlet.jsp.JspException: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: com.tonbeller.jpivot.olap.model.OlapException: 1
Any ideas? Thanks :)
This question is a direct copy oF your previous posts:
https://stackoverflow.com/questions/38970610/olap-report-with-optional-parameter
Is ${param} is a string?
If it is a string then the following should function:
WITH MEMBER [Measures].[x] AS ${param}
SELECT
NON EMPTY {[Measures].[x]} ON COLUMNS
FROM [TRANSACTIONS];
Does it function?
If it does not function then the question is not really mdx related - as for some reason your syntax or the way the parameter is moving to the client is wrong.
note
The above is the equivalent of this super simple script:
WITH
MEMBER [Measures].[x] AS "hello world"
SELECT
NON EMPTY
{[Measures].[x]} ON 0
FROM [Adventure Works];
Do you have AdvWrks cube? Try these:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(IsEmpty([Measures].[x])) //<< this returns False
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< this is what IIF returns
)
} ON 0
FROM [Adventure Works];
It returns this:
Now I tested out IsEmpty:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(NOT //<< added this to check functionality of IsEmpty
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS //<< this is what IIF returns
,{[Measures].[x]}
)
} ON 0
FROM [Adventure Works];
We get the following:
What I think is happening in your scenario is this - the param is not empty but is actually a zero length string:
WITH
MEMBER [Measures].[x] AS ""
SELECT
{
IIF
(
(
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< the zero length string goes to here
)
} ON 0
FROM [Adventure Works];
Results in:

SSRS: Expression with IIF in Join throws error

I have a field with below expression:
=join(iif(Parameters!FUP_Letter.Value = 1, "Yes", "No"), ", ")
When the report is loaded the field only says '#Error' instead of 'Yes, No', 'Yes' or 'No'
When I remove the IIF clause from this expression the result is just '1, 0' or '1' or '0'
As I am still new to SSRS I don't really know what I did wrong or how to find what I did wrong so if anyone could tell me the error or help me on my way I would be very grateful.
Kind regards
I suspect the error is being caused by you trying to join one value to nothing.
The IIF function isn't recursive, so it will return for the first value that you return so in the case above it will exit after evaluating 1 and returning yes. The join function then try's to join 'yes' to nothing and therefore errors.
you could do something like:
=Join(Replace(Replace(Parameters!FUP_Letter.Value,"1","Yes"),"0","No"), ",")
Actual used:
=Replace(Replace(join(Parameters!FUP_Letter.Value, ", "),"1","Yes"),"0","No")