Power Query 编辑器 - 根据多个条件编辑具有不同值的多个列

问题描述 投票:0回答:1

我正在使用 Power Query 编辑器,需要根据多个条件更改多个列。

目前,我使用 Table.ReplaceValue 分 3 个单独的步骤执行此操作,但每个迭代步骤中条件中的变量都会发生变化(因为第一步是 CommentCOPY = Comment,并且我依赖于仅在以下情况下发生的其他操作) CommentCOPY = ""),因此我需要根据第一个状态执行所有 3 个操作(或者换句话说,根据一组条件执行 3 个操作)。

我也只希望在某个条件成立时整个事情才能运行。

在我看来,我想做一些类似的事情:

if Scope = "A" then
if ActionNeeded ^="" and CommentCOPY ="" then do;
   CommentCOPY = Comment;
   Action = ActionNeeded;
   AssignedTo = "Manager";
   end;
;

但是我需要电量查询代码。这是初始表:

分配给 评论复制 行动 需要采取行动 评论 范围
用户1 1 现在就做 A
用户1 2 快点做吧 A
用户2 快点做吧 A
用户2 3 随时做 A
用户3 1 现在就做 A
用户3 2 快点做吧

结果:

分配给 评论复制 行动 需要采取行动 评论 范围
经理 现在就做 1 1 现在就做 A
经理 快点做吧 2 2 快点做吧 A
用户2 快点做吧 A
经理 随时做 3 3 随时做 A
经理 现在就做 1 1 现在就做 A
用户3 2 快点做吧

电量查询有能力做这种事情吗?

multiple-columns powerquery multiple-conditions
1个回答
0
投票

您可以使用此方法逐行进行转换,一次转换多列:

let
    Source = Excel.CurrentWorkbook(){[Name="Table41"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"AssignedTo", type text}, {"CommentCOPY", type any}, {"Action", type any}, 
        {"ActionNeeded", Int64.Type}, {"Comment", type text}, {"Scope", type text}}),

    #"Transform Multiple Columns" = 
        Table.FromRecords(
            Table.TransformRows(#"Changed Type",
                (r) => Record.TransformFields(r,
               {
                    {"CommentCOPY", each if r[Scope]="A" and r[ActionNeeded]<> null and r[CommentCOPY] = null 
                            then r[Comment] else _ },
                    {"Action", each if r[Scope]="A" and r[ActionNeeded]<> null and r[CommentCOPY] = null 
                            then r[ActionNeeded] else _ },
                    {"AssignedTo", each if r[Scope]="A" and r[ActionNeeded]<> null and r[CommentCOPY] = null 
                            then "Manager" else _ }
                }
            

                )))
in
    #"Transform Multiple Columns"

© www.soinside.com 2019 - 2024. All rights reserved.