Table of Contents

代码操作 DR011(可读性) 使用 ISBLANK 重写

说明

不要将表达式与 BLANK() 返回的值进行比较,而应使用 ISBLANK 函数。

示例

将以下代码:

IF(
    Document[Type] == BLANK(), 
    [Sales Amount], 
    [Sales Amount] * 1.25
)

改为:

IF(
    ISBLANK(Document[Type]), 
    [Sales Amount], 
    [Sales Amount] * 1.25
)

为什么 Tabular Editor 会建议这么做?

ISBLANK 函数能以更简洁、更易读的方式检查表达式是否返回空白值。 使用 ISBLANK 后,代码可读性更好,表达式的意图也更清晰。

备注

此代码操作仅适用于与 BLANK()严格相等比较(==)。 当 [Type] 为空字符串或零时,常规相等比较 Document[Type] = BLANK()ISBLANK(Document[Type]) 的结果并不相同(在这种情况下,ISBLANK(Document[Type]) 会返回 FALSE,而 Document[Type] = BLANK() 会返回 TRUE)。

延伸阅读