excel - Power Query Transform a Column based on Another Column -
i keep thinking should easy answer evading me. in excel power query, transform value in each row of column based on column's value. example, assume have table1 follows:
column | column b ------------------- x | 1 y | 2
i transform values in column based on values in column b, without having add new column , replace original column a. have tried using transformcolumns input can target column's value - can't access other field values in row/record within transformcolumns function. like able this:
=table.transformcolumns(table1, {"column a", each if [column b]=1 "z" else _ })
which result in:
column | column b ------------------- z | 1 y | 2
i know there ways this, i'm trying find 1 least amount of steps/transformations. example, know use table.addcolumn add new column based on function looks @ column b, have remove original column , replace new column requires multiple additional steps.
here how ended doing this:
table1: column | column b ------------------- x | 1 y | 2 = table.fromrecords(table.transformrows(table1, (r) => record.transformfields(r, {"a", each if r[column b]="1" "z" else _})))
result:
column | column b ------------------- z | 1 y | 2
this way can transform multiple columns @ once using nested list in record.transformfields function.
Comments
Post a Comment