SSRS: Expression with IIF in Join throws error - reporting-services

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

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

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:

Ms Access breaking DateDiff iif function

I have a calculated column to check if "Last Payment" is less than 90 days from "withdrawaldate". Expression:
IIf(DateDiff('d',[Last Payment],[withdrawaldate])<=90,'1')
If I edit this in sql view it works perfectly. However if i edit this using query builder it breaks and says "Invalid syntax" highlighting '1' as the invalid section.
"Last Payment" is also a calculated field if that makes any difference?
What am I missing??
Please help
Thanks in advance!
Edit
SQL view as Follows:
SELECT
Book.Cause_Date,
Book.Is_Archived,
Book.Status, Book.Handover_Status,
Max(Payments.[Capture Date]) AS [Last Payment],
Withdrawaltest.ACCOUNTNO,
Withdrawaltest.WITHDRAWALDATE,
Withdrawaltest.WITHDRAWALREASON,
IIf(Abs(DateDiff('d',[Last Payment], [WITHDRAWALDATE])<=90)='1',"Yes","No") AS [Paid in 90Days],
IIf((Abs(DateDiff('m',[Cause_Date],[WITHDRAWALDATE])<=14)='1' And [Handover_Status]='3') Or (Abs(DateDiff('m',[Cause_Date], [WITHDRAWALDATE])<=9)='1' And [Handover_Status]='1'),'No','Yes') AS [Out Of Term],
IIf([Paid in 90Days]="Yes" Or [Out Of Term]="No","KEEP","DontBother") AS [Keep?]
FROM
Payments RIGHT JOIN (Book INNER JOIN Withdrawaltest ON Book.Case_Reference = Withdrawaltest.ACCOUNTNO) ON Payments.[Case Reference] = Withdrawaltest.ACCOUNTNO
GROUP BY
Book.Cause_Date, Book.Is_Archived,
Book.Status, Book.Handover_Status, Withdrawaltest.ACCOUNTNO,
Withdrawaltest.WITHDRAWALDATE, Withdrawaltest.WITHDRAWALREASON,
IIf((Abs(DateDiff('m',[Cause_Date],[WITHDRAWALDATE])<=14)='1' And [Handover_Status]='3') Or (Abs(DateDiff('m',[Cause_Date],
[WITHDRAWALDATE])<=9)='1' And [Handover_Status]='1'),'No','Yes')
ORDER BY
Max(Payments.[Capture Date]) DESC;
First, your expression is missing the "False" part of the IIf:
IIf(DateDiff('d',[Last Payment],[withdrawaldate])<=90, '1', <FALSE-PART>)
Second, if you use German Access, then you must use ; instead of , for functions in Query design view.
IIf(DateDiff('d';[Last Payment];[withdrawaldate])<=90; '1'; <FALSE-PART>)
But in SQL view (that's "international") it is ,.

Keywords to make my Condition check correct in MS Access

I want a where condition in MS Access Query,
but i am not able to get that correct.
Here is the c# representation of my condition
If(vEmail==null)
return false;
else
return Email==vEmail
I want it to be translated into MS Access Query's where condition.
I dont know what are the keywords of MS Access query can be used here.
IIF(IsNull(vEmail), "False", vEmail) AS Email
This should do the trick. It says:
If vEmail Is Null (IsNull would result in true), then return "False", else return Email.
vEmail=Null Shouldn't work, because Null != Null. There are also a couple other ways you can check for null.
IsNull
Not IsNull
YourField Is Null
YourField Is Not Null

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