Check null and split value in textbox in SSRS report - reporting-services

I am facing very simple issue but not getting solution over it.
I have textbox in my ssrs report, I am passing value "1;prashant" or null to it. Now, if I pass value "1;prashant" to textbox then textbox should show only "prashant" and If I am passing nothing then it should be blank.
I have tried following IIF condition:
=IIF(IsNothing(FieldS!WIAPPORVER.Value),"",Split(Fields!WIAPPORVER.Value,"#")(1).ToString())
But, I above code is giving an error ["#error" shows in textbox] if I am passing blank value.
Please let me know, where I am wrong in this.
Thanks

There are probably better ways of doing this, but this is what my head came up with at the time:
=IIF(
IsNothing(Fields!WIAPPROVER.Value)
,""
,Right(Fields!WIAPPROVER.Value,Len(Fields!WIAPPROVER.Value) -InStr(Fields!WIAPPROVER.Value,";"))
)
I believe SSRS is trying to compute everything in the report at runtime, so in your case it is still trying to fetch index 1 from an array even though there is nothing in it and it crashes.
Edit: Changed parameters to Fields. I created a parameter to remake the issue at my side.

Just get the split out of the iif. Then in your iif, if field is nothing create a string that when split will return ""
=Split(IIF(IsNothing(FieldS!WIAPPORVER.Value),"#", Fields!WIAPPORVER.Value),"#")(1)

You are relying on the IIf expression short circuiting, but SSRS IIf expressions do not short circuit - the expression will try and work out Split(Fields!WIAPPORVER.Value,"#")(1).ToString() for all rows and fail when this value doesn't exist.
You can get this going by using text expressions, which don't get this error.
With test data:
And a simple table:
I have added columns with both your existing expression and a new expression:
=Right(Fields!WIAPPORVER.Value, Len(Fields!WIAPPORVER.Value) - InStr(Fields!WIAPPORVER.Value, "#"))
This new expression works for NULL values, empty strings and strings with no delimiter present:

Related

How to get around '#Error' when a function in MS Report Builder is evaluating a null value?

I hope my title is clear enough. I'm working in MS Report Builder, using a function that applies a regular expression to a queried value in order to get back a certain substring. The regex works fine, so I'll demonstrate a simpler version here to make this less wordy. Here's the gist of my equation:
=IIF(Len(Fields!CourtLocation.Value) < 1, "none",System.Text.RegularExpressions.Regex.Match(Fields!CourtLocation.Value, "(?:[A-Z]{2,4})").Value))
The main purpose is to get that substring, but I added the IIF so that on those occasions when the CourtLocation.Value is empty (I tried Is Nothing in my expression as well), the function returns "none" rather than "#Error"
I've been looking around for a solution, but nothing has worked; it seems like most other people who talk about this are using a mathematical equation rather than trying to get a string. Can anyone help me get rid of that stupid "#Error" value?
You could try this (untested)
=System.Text.RegularExpressions.Regex.Match(
IIF(
Len(Fields!CourtLocation.Value) < 1,
"none",
Fields!CourtLocation.Value
)
, "(?:[A-Z]{2,4})"
).Value
This way the IIF is performed on the string that you want to pass to the regex function, so it always gets a valid value to process
Iif evaluates both sides, so you can nest two Iif statements to avoid the error.
Did you already read this one?
https://sqldusty.com/2011/08/01/ssrs-expression-iif-statement-divide-by-zero-error/
I'll copy the text into the answer if that solves it for you.

#Error in Column With both Text and Numeric Values in ssrs reports

In my report for one field i have both numeric and text values.( i.e 10.546 and "vary")
So when i apply CDec function for this field values i get #error where i have filed value as "Vary" .
10.6572 10.6572
Vary #Error
i tried expression "
=IIf(IsNumeric(Fields!price.Value),
CDec(Fields!price.Value),
"Fields!price.Value)"
but it is not working.
i checked in net in most of the cases all telling to write function, unfortunately in my project that is not allowed.
so is their any way i can resolve this "#Error" using expression.
I got solution.
=iif(IsNumeric(Fields!EUnit.Value), VAL(Fields!EUnit.Value),Fields!EUnit.Value)
this is working fine to me.
Ref : https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ac2c9db4-85a5-44a8-909b-1ee09791542e/ssrs-check-if-the-field-value-is-numeric-or-not?prof=required

Dealing with blank or null in ssrs

In my report, I have an expression which is used to pass a parameter to a child report parameter which is set to allow null values. The expression is :
=IIf(Parameters!Lead.Value = "False",Nothing,Fields!Paid.Value)
The above expression returns values only when Fields!Paid.Value is not blank. Therefore when Fields!Paid.Value is blank I get an error
"the value provided for the report parameter is not valid"
How do I modify my expression to parse these two conflicting issues?
What I want is to be able to return values when the Fields!Paid.Value is blank or when it is not. So at all time when the expression runs corresponding values are returned without the error stated above.
Thanks for helping out.
The first thing you do, wherever you have used the "Paid" parameter, set it to allow null value. Allow null only not blank.
The second thing about the expression, use something like this,
=IIF(Parameters!Lead.Value "FALSE", Nothing, IIF(IsNothing(Fields!Paid.Value),0,Fields!Paid.Value)

Type Problems with Filter Expression in SSRS

SQL Server 2008 R2, using BIDS to design the report.
I have a table and I am trying to only show a certain row. Maybe there are better ways to do this, but I am coming across an error with the filter expression and regardless of how I achieve my initial task, I'd like to understand the filtering.
I started with the filter expression (set to type "Integer"):
RowNumber(Nothing) = 1
This gave the error:
Cannot compare data of types System.String and System.Int32.
I found the solution to this is to change the 1 to "=1" as 1 is evaluated as a string.
So I then had:
RowNumber(Nothing) = =1
That changed nothing, I got the same error.
Then I tried to do that to the first part of the expression:
=RowNumber(Nothing) = =1
This changed the error to a deployment problem (still builds, which is frustrating):
Error pvInvalidDefinition : The definition of the report '/ReportName' is invalid.
I then tried using CInt on RowNumber:
CInt(RowNumber(Nothing) = =1
Then I can deploy it, but the error just changes back to the first one:
Cannot compare data of types System.String and System.Int32.
It seems no matter what I try here I either can't deploy the report or I get an error that I'm comparing a string to an int.
RowNumber returns an integer, so it seems like this should work. I've tried using the name of the dataset in place of "Nothing" but that doesn't change what I'm seeing.
I realize there are many ways to solve my initial problem, but I am curious as to why the filter expression is invalid.
Its better to hide a row with visibilty property. Just click on any text box and go to visibily tab . You can now click on show or hode and go to expression.
That default to Hide . So write an expression there to hide the row.
=IIf(NOT(RowNumber = 1),TRUE,FALSE)
Let me know if you get any error
RowNumber is not available to use in a Tablix Filter.
Using RowNumber(Nothing) <> 1 as a Row visibility property fixed the issue.
Using BIDS you are not given any error that indicates what the problem is, but importing the report to Report Builder and deploying it from there will give a more descriptive error that, in the end, helped me to solve my problem.

Adding Fields into an expression in an SSRS 2008 report

Thank you in advance for taking your time to answer my question.
I am having trouble with expressions in the SSRS reporting system.
The Field I am adding required fields from the dataset I provided in the report, however when I try to preview the report I get the Following message:
"A Value expression used for the report parameter ‘Policies_Total’
refers to a field. Fields cannot be used in report parameter
expressions."
This is my expression:
=IIF(Sum(Fields!policy_id.Value, "DataSet1") Is Null, 0, Count(Sum(Fields!policy_id.Value, "DataSet1")))
That was suppoed to be converted from Crystal reports which has the following expression:
If IsNull ({usp_rep_agent_cases;1.policy_id}) then
0
Else
Count ({usp_rep_agent_cases;1.policy_id})
Any help is much appreciated.
Thank you
I think it may be as simple as understand that a 'parameter' should be passed into SSRS before fields are created for the most part. If this parameter is DEPENDENT on the value of something else first being chosen you cannot list it first as the field is not yet populated to my knowledge. It appears you are trying to use an expression to count something from a field from a dataset when you just make a dataset and reference that field directly. So instead of trying an expression you may choose a few other options instead:
Choose on the left pane of your parameter 'Available Values' selected 'Get values from a query'. You may use your query which is a 'dataset', value is self explanatory, label is what the end user will see display.
The option 'Allow null' value will accept a null value
You may run into situations where multiple datasets may need to be used, multiple selects or querying objects. In my experience with SSRS it gets mad at times when you try to reference a dataset used to display data with a dataset used to determine an event or action. SSRS also gets relativity slower the more Expressions you do so doing a whole report with nothing but expressions versus taking the power of the built ins of the RDL language is not really worth it IMHO.
For SSRS expressions you need to use IsNothing for NULL checking, something like:
=IIF(
IsNothing(Sum(Fields!policy_id.Value, "DataSet1"))
, 0
, Count(Sum(Fields!policy_id.Value, "DataSet1"))
)
In fact the whole expression seems a bit odd; what are you specifically trying to achieve with your expression? Are you just trying to count non-null values?
=Sum(IIf(IsNothing(Fields!policy_id.Value), 1, 0), "DataSet1")
Also, your error seems to be saying that a parameter is referencing a field when this isn't allowed, which may not be solved by changing syntax; I think more information about what you're trying to achieve is required here.