首页 > 解决方案 > Power Bi 自定义列功能

问题描述

在 MQuery 中,我正在尝试创建一个自定义列。如果另一列的值介于 1 到 5 之间,则新列中的值将是一些文本。它给了我一个 Token Else 预期错误。

=if[#"Chair Independence Level"] = "1" then "Same Product Line" 
else if[#"Chair Independence Level"]= "2" then "Different Product Line" 
else if[#"Chair Independence Level"]= "3" then "Different Business Area" 
else if[#"Chair Independence Level"]= "4" then "Different Sector" 
else if [#"Chair Independence Level"]= "5" then "Not an Employee"

有谁知道如何解决问题或我应该将代码更改为什么?

标签: powerbi

解决方案


Power 查询中的 IF 条件需要使用 ELSE 语句来限制。只需添加 ELSE 就可以了:

=if[#"Chair Independence Level"] = "1" then "Same Product Line" 
else if[#"Chair Independence Level"]= "2" then "Different Product Line" 
else if[#"Chair Independence Level"]= "3" then "Different Business Area" 
else if[#"Chair Independence Level"]= "4" then "Different Sector" 
else if [#"Chair Independence Level"]= "5" then "Not an Employee"
else "NA"

如果 #"Chair Independence Level" 字段是数字,则:

=if[#"Chair Independence Level"] = 1 then "Same Product Line" 
else if[#"Chair Independence Level"]= 2 then "Different Product Line" 
else if[#"Chair Independence Level"]= 3 then "Different Business Area" 
else if[#"Chair Independence Level"]= 4 then "Different Sector" 
else if [#"Chair Independence Level"]= 5 then "Not an Employee"
else "NA"

推荐阅读