基于另一列更改 Power Query 中的一列

Change a column in PowerQuery based on another column

我尝试在 Excel PowerQuery 中使操作与 SQL 操作相同:

SET ColumnA = "Max" WHERE ColumnC = "George" 

我知道我可以 CREATE 使用 M 表达式

的新 Column
if ColumnA = "Max" then "George" Else "something" 

但我不喜欢创建第三列,因为我一次又一次地这样做。

有什么办法可以做到这一点吗?

您可以将 if 语句链接在一起,就像这样

if [ColumnA] = "Max" then "George" else if [ColumnA] = "Jane" then "Janet" else "something"

您还可以创建一条记录来查找姓名,然后使用备用姓名(如果存在)。这可以通过在一个查询中创建这样的记录来完成:

let
    Source = [Max = "George", Jane = "Janet"]
in
    Source

将该查询命名为名称。然后,当您添加自定义列时,您可以使用此表达式:

if Record.HasFields(Names, [ColumnA]) then Record.Field(Names, [ColumnA]) else "something"

希望对您有所帮助。