SSRS : Empty string from webservice errors even with iif statements - reporting-services

I am using a web service to get back a value. Which when not needed is empty string. However no matter what I do to try and code for if it is empty is always errors :
=iif( Fields!X.Value="","",iif(IsNumeric(Fields!X.Value) ,CStr(CDbl(Fields!X.Value) * 100),""))
Thanks for any help
Ian

Try the following...
=IIF(
IsNumeric(Fields.X.Value),
Val(Fields.X.Value) * 100,
""
)
If X is not numeric you will get and empty string, if X is zero you will get 0 returned and if X is numeric you will get X *100

Related

Why am I getting type mismatch from label in access form?

I am getting values from labels that are formatted as Percent (0.00%).
Therefore, I cast it to a double CDBL(label.caption) and I get the type-mismatch error.... see my code:
Forms(frmName).Label80.Caption = format(CDbl(Forms(frmName).Label123.Caption) + CDbl(Forms(frmName).Label162.Caption), "Percent")
Originally:
label123 has 10.00% value and label162 has 0.00% value
so if I do cdbl(label123) it gives me 10 (good!)
if I do cdbl(label162) it produces an error
if I do val(label162) it produces an error
I'm thinking it has something to do with 0?? I can't seem to figure this out...
You can also use the Format function to parse the percentage and return a string containing the equivalent value in General Number format, so that it may be successfully converted using the CDbl function, e.g.:
Forms(frmName).Label80.Caption = Format(CDbl(Format(Forms(frmName).Label123.Caption, "General Number")) + CDbl(Format(Forms(frmName).Label162.Caption, "General Number")), "Percent")
The advantage of this method is that the Format function recognises that the string represents a percentage and therefore automatically handles the division by 100:
?Format("10.48%", "General Number")
0.1048
The use of CDbl also allows for regional differences in decimal number representation (e.g. the use of a comma in place of a period) - my thanks to #Gustav for pointing this out.
Try removing the % signs:
Forms(frmName).Label80.Caption = Format(Val(Replace(Forms(frmName).Label123.Caption, "%", "")) + Val(Replace(Forms(frmName).Label162.Caption, "%", "")), "Percent")
Edit:
Using Val, only works having dot (.) as the decimal separator.
For a universal solution, use CDbl or CCur as these convert the localised format correctly where a value formatted as percent may display as 10,48%.
Forms(frmName).Label80.Caption = Format(CDbl(Replace(Forms(frmName).Label123.Caption, "%", "")) + CDbl(Replace(Forms(frmName).Label162.Caption, "%", "")), "Percent")
Use the following template for each label. The evaluate takes care of the percent sign.
L0 = CDbl(Evaluate(Label0.Caption))

SSRS error Index was outside the bounds of the array. (rsRuntimeErrorInExpression)

I am building a report in SSRS and i am getting an the error: Index was outside the bounds of the array (rsRuntimeErrorInExpression).
I have tried different expressions to fix this but I can't make it work. I currently have:
=iif(LEN(Fields!Comment.Value) - LEN(REPLACE(Fields!Comment.Value, ",","")) > 3, Split(Fields!Comment.Value, ",")(3), Nothing)
Could anyone advice me how to solve this?
The error has to do with SSRS trying to evaluate the split expression even if the Iif condition is false.
Instead of the static value of 3 as the array index you can use a nested Iif to return a valid index value like 0, to make split always work.
=iif(
LEN(Fields!Comment.Value) - LEN(REPLACE(Fields!Comment.Value, ",","")) >3
, Split(Fields!Comment.Value, ",")(
iif(
LEN(Fields!Comment.Value) - LEN(REPLACE(Fields!Comment.Value, ",","")) >3
,3
,0
)
)
, Nothing
)

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:

IIF in SSRS returning an error

I have an SSRS report that is throwing and #ERROR# in the field.
I am comparing Down Time to Total time...DownTime/TotalTime, to get a percentage of downtime over all time.
The original code was:
=Sum(Fields!PrevYear_Total_Down_Time.Value)
/
Sum(Fields!PrevYear_Total_Time.Value)
This threw an #ERROR# which I assumed was due to "Sum(Fields!PrevYear_Total_Time.Value)" being zero or null, so I adjusted the code to an IIF statement:
=IIF(Sum (Fields!PrevYear_Total_Time.Value)=0,0,
IIF(Sum(Fields!PrevYear_Total_Down_Time.Value)=0,0,
Sum(Fields!PrevYear_Total_Down_Time.Value)/Sum(Fields!PrevYear_Total_Time.Value)
)
)
If I replace the second nested IIF statement with a number, it works and puts whatever number I designate, But, that is NOT what I wanted. I want to test for zero, or null, and if the Total Downtime is null or 0, return 0.
Solved it by writing a code snippet that passes the two values then returns the formatted value.
The other way is to put another IIF in the denominator to account for the zero:
=IIF(Sum(Fields!PrevYear_Total_Time.Value) = 0, 0, Sum(Fields!PrevYear_Total_Down_Time.Value))
/
IIF(Sum(Fields!PrevYear_Total_Time.Value) = 0, 1, Sum(Fields!PrevYear_Total_Time.Value))

Replace #Error or NAN with -(hyphen) in SSRS

When i get a value into the text box (say "NAN" or "#Err") i want to replace it with -(hyphen).
How to achieve this in SSRS reporting ?
Thanks in advance.
You'll need to write an expression to handle it. Ideally, you would have some custom code function in your report (ie. Code.SafeDivision())
=iif(Fields!denominator.Value = 0, "-", Numerator / Denominator)
To elaborate on cmotley's answer, add the following as custom code to your report (to do this go to report properties, then code and then paste this in):
Function SafeDivide(value1 As Decimal, value2 As Decimal) As Decimal
If (value1 <> 0.0 And value2 <> 0.0) Then
Return value1 / value2
Else
Return 0
End If
End Function
Then you can use this in your textboxes to divide without receiving not a number and/or error, for example, adding the following as an expression (changing textbox names as required):
=Code.SafeDivide(ReportItems!Textbox186.Value, ReportItems!Textbox184.Value)
Divides two textboxes using our function.
To show a dash you can simply change the formatting of your textbox to 'number' and tick the box indicating that you'd like to replace '0' with '-'.
Alternatively if for some reason 'NaN' is coming through explicitly from a datasource (rare but not impossible when referencing a loaded table in SharePoint) you could use the following:
Function evalutator(value as String) as String
Select Case value
Case "NaN"
Return "-"
Case "NAN"
Return "-"
End Select
Return value
End Function
What about:
=IIF(Fields!yourcolumnname.Value = 0, "-", Fields!yourcolumnname.Value*1)
Or if you wanted zero's where you get NAN/#ERROR then you could use:
=IIF(Fields!yourcolumnname.Value = 0, Fields!yourcolumnname.Value*1, Fields!yourcolumnname.Value)