Conditional Column Based on List Membership in Power Query M

Flags rows where a column's value matches any item in a predefined list.

Conditional LogicBeginnerlist.containsmembershipconditional

Power Query M code

let
    Source = YourTable,
    TargetRegions = {"West", "East", "Central"},
    AddedFlag = Table.AddColumn(Source, "IsTargetRegion", each List.Contains(TargetRegions, [Region]), type logical)
in
    AddedFlag

Notes

Update TargetRegions with the values you want to match against - this scales better than a long chain of or conditions.

Requirements

How to use this snippet

  1. In Power BI Desktop, choose Transform data to open Power Query, then open the Advanced Editor on a query (or start from a blank query).
  2. Paste the snippet and replace the placeholder names (tables, columns, file paths) with your own. Check the requirements above first.
  3. Run it through the Power Query M Formatter to tidy the layout.

Related Power Query M snippets

More Power Query M resources

Browse all 145 snippets in the Power Query M Code Snippets, or search the library for something similar to Conditional Column Based on List Membership.