SSRS Expression error handling - reporting-services

I am using the following expression in one of my report fields.
=Fields!Value.Value*(Fields!DutyRate.Value/100)
This works as exprected as long as there is a valid value in the Fields!DutyRate.Value.
My problem is that the Fields!DutyRate.Value can contain non numerical values such as "Free".
This means any rows with the word "Free" in them causes an #Error. This is OK as such but I would like to get SSRS to display something other than #Error. In fact I would like to to display "F" instead.
Many thanks

You can use an IIF (inline if statement) and the IsNumeric function.
Syntax: IIF(<condition>,<true part>,<false part>)
=IIF(IsNumeric(Fields!DutyRate.Value),Fields!Value.Value*(Fields!DutyRate.Value/100),"F")
SSRS Expression Examples
Visual Basic Functions (SSRS expressions use VB functions)

Related

what countrows().equals() means in SSRS

I can't understand the structure of the written code
(CountRows("client_code").Equals(Parameters!client_code.Count)
can anyone explain this please?
And where can I find a reference for all the functions that I can use to write Expression in SSRS??
In SSRS we use "=" operator for comparison rather than equals.
Expression mentioned by you below
(CountRows("client_code").Equals(Parameters!client_code.Count)
Rather it should be like
=IIF(CountRows("client_code")=Parameters!client_code.Count,true,false)
What your mentioned code does: It Returns a count of rows within the specified scope, Scope can be Group as well. and it compared with your Report Parameter count.
Here you will find complete list of functions and expression for SSRS.

SSRS expression not working properly

I have one expression in my SSRS report which use to display currency data in the report. When there is no data NULL in the particular row it should display $0. However, it is displaying #Error.
=IIF(Fields!Value.Value="Nothing","$0",FormatCurrency(Fields!Value.Value,0))
I tried with IsNothing function as well but getting same result.
Take the quotes off Nothing..
=IIF(Fields!Value.Value=Nothing,"$0",FormatCurrency(Fields!Value.Value,0))

LIKE operator in SSRS row visibility expression

I have a text box within an rdl report which I want to suppress based on certain terms in my dataset (i.e. if the query returns a term which ends with the letter "L" then hide the text box).
Within the textbox properties I have set visibility expression for Hidden with the below expression:
=First(Fields!STERMS__.Value, "Job") NOT LIKE '%L'
When I run it I get the error:
"The Visibility.Hidden expression for the text box contains an error:
[BC30201] Expression expected"
It seems like a schoolboy error but I have tried various permutations on this expression with no luck. Any help would be appreciated.
SSRS expressions are funny in some ways. I think what you're looking for is:
=IIf(First(Fields!STERMS__.Value, "Job") Like "*L", True, False)
The gist is that SSRS doesn't use SQL syntax. It's VB
I think you could use the Right() function which returns a specified number of characters from the right hand side of a string.
E.g.
=Right(Fields!STERMS__.Value,1)
I guess in your case for Hidden property on the cell, the expression would look like this
=IIF(Right(First(Fields!STERMS__.Value, "Job"),1)=="L",true,false)

Check null and split value in textbox in SSRS report

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:

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.