iif (Iserror ()) function still returning #error

試著忘記壹切 提交于 2020-01-03 09:18:10

问题


I have the following function that creates a column in my query:

MTD: IIf(IsError(FormatNumber([62xx]![F40])),0,FormatNumber([62xx]![F40]))

This is linked to an Excel file and where people put numbers and text in the same column (F40 in this example). I need to know if the thing I am looking at is a number or text. If it's text I want a zero, if it is a number I want the number. I know that when I use FormatNumber([C107_62xx]![F40]) on a text line I get an error. I would assume when I get an error, then my iif formula above would convert that to a zero and the world would rejoice. For some reason I am still getting a #error even with my iif statement. What am I doing wrong?

I have also tried using the IsNumeric function but I still get #NUM! errors that come through.


回答1:


IsError does not do what you think it does. From the help topic, it "Returns a Boolean value indicating whether an expression is an error value." Not whether the expression triggers an error, but whether the expression is an error value.

Sorry, that explanation was probably not clear enough, but I don't know how to do better. So I'll just suggest you consider this IsNumeric() expression for what you want here.

IIf(IsNumeric([62xx]![F40]), FormatNumber([62xx]![F40]), 0)

Here is that same expression in a query with the output below.

SELECT
    [62xx].F40,
    IIf(IsNumeric([62xx]![F40]), FormatNumber([62xx]![F40]), 0) AS MTD
FROM [62xx];
F40    MTD
-----  ----
foo    0
1      1.00
2.345  2.35
bar    0


来源:https://stackoverflow.com/questions/22670418/iif-iserror-function-still-returning-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!