Power Query Transform a Column based on Another Column

前端 未结 6 1980
谎友^
谎友^ 2020-12-16 05:10

I keep thinking this should be easy but the answer is evading me. In Excel Power Query, I would like to transform the value in each row of a column based on another column\

6条回答
  •  独厮守ぢ
    2020-12-16 05:27

    Here is how I ended up doing this:

    Table1:
    Column A | Column B
    -------------------
    X        | 1
    Y        | 2
    
    = Table.FromRecords(Table.TransformRows(Table1,
        (r) => Record.TransformFields(r,
            {"A", each if r[Column B]="1" then "Z" else _})))
    

    Result:

    Column A | Column B
    -------------------
    Z        | 1
    Y        | 2
    

    This way you can transform multiple columns at once by using a nested list in the Record.TransformFields function.

提交回复
热议问题