You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power BI查询中SWITCH函数未被识别,自定义列表达式报错求助

Fixing the SWITCH Function Error in Power BI Power Query Custom Column

Looks like you ran into a classic mix-up between DAX and Power Query M language syntax—plus a tiny spelling error that was adding to the confusion. Let's break down what went wrong and fix it:

Key Issues in Your Original Code

  • Wrong SWITCH Syntax for M Language: Unlike DAX, Power Query's SWITCH doesn't use assignment expressions (like Empolyees = "Chris1") in the result branches. You just need to return the value you want the new column to have directly.
  • Typos: You misspelled "Employees" as "Empolyees" (missing the letter 'y') in both the new column name and the branch expressions.
  • Incorrect Result Structure: Each pairing in M's SWITCH should be [Matching Value], [Result Value], not a conditional assignment.

Corrected Code

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

What Changed?

  1. Fixed the Spelling: Renamed the new column and corrected all references to "Employees" (no more missing 'y').
  2. Adjusted SWITCH Branches: Instead of writing Empolyees = "ChrisX", we just return the string value "ChrisX" directly—this is how M language assigns values to the new column.
  3. Preserved Valid Structure: Kept the core logic of matching the [Index] column values to your desired names, with BLANK() as the fallback for unlisted index numbers.

A quick reminder: If you were trying to create a DAX calculated column instead of a Power Query custom column, your original syntax would be closer to correct (with the spelling fix), but since you're using Table.AddColumn, we're working in M language here—hence the syntax differences.

内容的提问来源于stack exchange,提问作者Cosq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:00:06