Search code examples
powerbipowerquerym

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

Solution

  • Try

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