Table of Contents

代码操作 DR012(可读性) 移除不必要的 BLANK

描述

某些 DAX 函数,例如 IFSWITCH,在条件为 false 时本就会返回 BLANK(),因此无需显式指定 BLANK()

示例

修改前:

SWITCH(
    Document[Type],
    "Invoice", [Invoice Amount],
    "Credit Note", [Credit Note Amount],
    BLANK()
)

修改后:

SWITCH(
    Document[Type],
    "Invoice", [Invoice Amount],
    "Credit Note", [Credit Note Amount]
)

为什么 Tabular Editor 会这样建议?

IFSWITCH 函数中,将 BLANK() 用作最后一个参数是多余的,因为这些函数在条件不满足时本来就会返回 BLANK()。 移除 BLANK() 后,代码会更简洁,也更易读。