查询中无法识别电源双开关

Cle*_*Ong 2 m dax powerbi powerbi-datasource powerbi-desktop

已使用以下代码创建自定义列,但它陷入表达式错误,无法识别 SWITCH 函数:

= Table.AddColumn(#"Removed Columns", "Empolyees", each SWITCH([Index],  
1, Empolyees = "Chris1",   
2, Empolyees = "Chris2",
3, Empolyees = "Chris3",
4, Empolyees = "Chris4", 
5, Empolyees = "Chris5",
6, Empolyees = "Chris6",
7, Empolyees = "Chris7",
8, Empolyees = "Chris8",
BLANK()
))
Run Code Online (Sandbox Code Playgroud)

我尝试过删除引号,更改列名,但都无济于事。请建议。提前致谢!

Fox*_* Ng 5

您混淆了M 和 DAX。它们是两种不同的语言,并且都在 Power BI 中使用。SWITCH()是一个 DAX 函数,因此不能在您正在编写的代码中使用它M query

您可以用 M 中的表达式SWITCH替换逻辑:if-then-else

= Table.AddColumn(#"Removed Columns", "Employees", each if [Index] = 1 then "Chris1" else if [Index] = 2 then "Chris2" else if [Index] = 3 then "Chris3" else if [Index] = 4 then "Chris4" else if [Index] = 5 then "Chris5" else if [Index] = 6 then "Chris6" else if [Index] = 7 then "Chris7" else if [Index] = 8 then "Chris8" else "")
Run Code Online (Sandbox Code Playgroud)

结果

取决于您想要实现的具体目标,可以使用其他函数,但我现在将保持这种方式,而不是做出假设。