查询中无法识别电源双开关
power bi switch is unrecognized in query
已使用以下代码创建自定义列,但卡在无法识别 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()
))
我试过删除引号,更改列名,但都没有 avail.Please 建议。提前致谢!
你搞混了 M and DAX. They are two different languages, and both are used in Power BI. SWITCH() 是一个 DAX 函数,因此它不能用在你写的 M query
中。
您可以用 M:
中的 if-then-else
expression 替换 SWITCH
逻辑
= 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 "")
具体看你想实现什么,也可以使用其他函数,但我暂时保持这种方式,而不是做任何假设。
将员工列表存储在 table 中并将其与您的查询合并会更好。您可以在查询中生成 table - 例如:
let
Source = Excel.CurrentWorkbook(){[Name="MyTable"]}[Content],
TempTable = #table(
{"ID","Name"},{
{1,"Employee 1"},
{2,"Employee 2"},
{3,"Employee 3"},
{4,"Employee 4"},
{5,"Employee 5"}
}
),
#"Merged Queries" = Table.NestedJoin(Source,{"ID"},TempTable,{"ID"},"Join",JoinKind.LeftOuter),
#"Expanded Join" = Table.ExpandTableColumn(#"Merged Queries", "Join", {"Name"}, {"Name"})
in
#"Expanded Join"
更好的做法是将员工 ID/姓名存储在单独的 table 中,然后以相同的方式加入。
已使用以下代码创建自定义列,但卡在无法识别 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()
))
我试过删除引号,更改列名,但都没有 avail.Please 建议。提前致谢!
你搞混了 M and DAX. They are two different languages, and both are used in Power BI. SWITCH() 是一个 DAX 函数,因此它不能用在你写的 M query
中。
您可以用 M:
中的if-then-else
expression 替换 SWITCH
逻辑
= 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 "")
具体看你想实现什么,也可以使用其他函数,但我暂时保持这种方式,而不是做任何假设。
将员工列表存储在 table 中并将其与您的查询合并会更好。您可以在查询中生成 table - 例如:
let
Source = Excel.CurrentWorkbook(){[Name="MyTable"]}[Content],
TempTable = #table(
{"ID","Name"},{
{1,"Employee 1"},
{2,"Employee 2"},
{3,"Employee 3"},
{4,"Employee 4"},
{5,"Employee 5"}
}
),
#"Merged Queries" = Table.NestedJoin(Source,{"ID"},TempTable,{"ID"},"Join",JoinKind.LeftOuter),
#"Expanded Join" = Table.ExpandTableColumn(#"Merged Queries", "Join", {"Name"}, {"Name"})
in
#"Expanded Join"
更好的做法是将员工 ID/姓名存储在单独的 table 中,然后以相同的方式加入。