This is a migrated thread and some comments may be shown as answers.

problem with complex expression

1 Answer 207 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
kellyroberts asked on 04 May 2010, 06:45 PM
Hi All -

oiy! this one is a pain.  I have a column in a dataset that is technically string but in reality has both string and numeric values.  well I want to test for numeric values ... and then format accordingly. so for example suppose i have a dataset that goes ...


I want the format to be currency. here is my expression.  *IsNumeric is a UDF that simply wraps Microsoft.VisualBasic.IsNumeric.*

=iif(IsNumeric(Fields.[YTD Target]),Format("{0:c}",CDbl(Fields.[YTD Target])),Fields.[YTD Target])

well the report bombs on 'apple' citing 'Input was not in correct format.

The only thing I can figure is that both True and False parts are fully evaluated when IIF is called.. so in the case of 'apple' the True part will surely fail eventhough isNumeric("apple") = False

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 06 May 2010, 09:55 AM
Hello kellyroberts,

The experienced behavior is correct and by design. As you can see IIF() is a Function and you need to prepare the parameters prior to executing the function. 

That's why the reporting engine first evaluates the function parameters and then pass the values to the function. 

Our suggestion would be to use an User Function instead of IIF as shown in the code snippet:
Public Shared Function CustomFormat(ByVal value As String) As String
    If IsNumeric(value) Then
        Return FormatCurrency(Convert.ToDouble(value))
        Return value
    End If
End Function

Give it a try and let us know how it goes.

All the best,
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question