Michal Palko
Michal Palko

Reputation: 661

Select rows based on variable column name

This does not seem difficult, but I am stacked here. I want to reference table column by variable name for filtering and cannot understand why this is not working.

let
    Source = Table.FromRecords({
    [VarColumn = "Val",  Phone = "123-4567"],
    [VarColumn = "Val2",  Phone = "987-6543"],
    [VarColumn = "NA",  Phone = "543-7890"],
    [VarColumn = "OTHER",  Phone = "543-7890"]
    }),

    VariableColumn = "VarColumn",
    filter = Table.SelectRows(Source, each (Table.Column(Source, VariableColumn) = "OTHER"))
in
    filter

Upvotes: 2

Views: 1106

Answers (1)

horseyride
horseyride

Reputation: 21318

Try

    filter = Table.SelectRows(Source, each Record.Field(_, VariableColumn) = "OTHER")

Upvotes: 2

Related Questions