To create an OR statement in Power Query, you use the or operator in a custom column formula or select multiple checkboxes in a filter menu. This achieves a logical "either/or" result, meaning the condition is met if at least one of the specified criteria is true. For example, if you want to find rows where a city is either "New York" or "London," an OR statement allows you to capture both without creating separate queries.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • A dataset loaded into the Power Query Editor.
  • Basic familiarity with the Power Query interface (Ribbon and Query Settings pane).

Step-by-Step

Method 1: Using the Filter Menu (No Coding)

The simplest way to perform an OR operation is through the built-in filter interface. This is ideal for basic column filtering where you want to include multiple specific values.

  1. Open the Power Query Editor by selecting Data > Get Data > Launch Power Query Editor in Excel, or by clicking Transform Data in Power BI.
  2. Locate the column you wish to filter.
  3. Click the filter arrow (dropdown) in the column header.
  4. In the list of values, check the boxes for every item you want to include. For instance, if you check "Red," "Blue," and "Green," Power Query treats this as: "Color equals Red OR Color equals Blue OR Color equals Green."
  5. Click OK. Power Query automatically generates the M code in the formula bar using or logic.

Method 2: Using a Custom Column (M Formula)

When you need to create a new category or a flag based on multiple columns or complex conditions, you must use a Custom Column. Note that Power Query is case-sensitive; or must be written in lowercase.

  1. Navigate to the Add Column tab on the ribbon.
  2. Select Custom Column.
  3. In the New column name box, give your column a descriptive name (e.g., "Priority Flag").
  4. In the Custom column formula box, start with an if statement. The basic syntax is: if [Column1] = "ValueA" or [Column2] = "ValueB" then "Yes" else "No".
  5. To add more conditions, simply continue adding or operators. For example: if [Status] = "Urgent" or [Status] = "Overdue" or [DaysOpen] > 30 then "Action Required" else "On Track".
  6. Click OK. Power Query will create a new column applying this logic to every row.

Method 3: Using Conditional Columns (UI-Based)

While the Conditional Column tool is primarily designed for "Else If" (which acts like an AND or a sequence), you can mimic OR logic by creating multiple rules that result in the same output.

  1. Go to the Add Column tab and select Conditional Column.
  2. Set your first rule: If [Column] equals "Value A", then output "Match".
  3. Click Add Rule.
  4. Set the second rule: If [Column] equals "Value B", then output "Match".
  5. Set the Else value to "No Match".
  6. Because both rules lead to the same "Match" output, the result is functionally an OR statement.

Common Mistakes

One of the most frequent errors is using uppercase letters. In the M language, OR or Or will trigger a syntax error; it must be strictly or. Similarly, if, then, and else must all be lowercase.

Another common mistake is forgetting that Power Query treats null values differently than empty strings. If you write , it will work, but if you try to perform a mathematical operation on a null value within an OR statement, the entire row may return an error. Always check for nulls first if your data is inconsistent.

Users also often confuse the OR operator with the AND operator. Remember that or requires only one condition to be true for the whole statement to be true. If you use or when you actually meant and, you will end up with far more rows in your filtered list than intended.

Tips

For lists with many OR conditions (e.g., filtering for 20 different product codes), writing or twenty times is inefficient and prone to typos. Instead, create a separate "Mapping Table" containing all the values you want to filter for. Then, use a Merge (Join) operation. A "Left Semi Join" will effectively act as a massive OR statement, keeping only the rows in your main table that have a match in your mapping table.

When combining and and or in the same formula, always use parentheses to define the order of operations. Power Query follows standard logic precedence. For example: if ([Region] = "West" or [Region] = "East") and [Sales] > 1000 then "High" else "Low". Without the parentheses, the logic might be interpreted as: "Either the region is West, OR (the region is East AND sales are over 1000)," which produces a completely different result.

To make your formulas easier to read, you can add line breaks in the Custom Column dialog by pressing Shift+Enter. This allows you to stack your OR conditions vertically, making it much easier to audit the logic later.

Troubleshooting

If your OR statement is returning "Error" for some rows, the most likely cause is a data type mismatch. For example, if you try to compare a text column to a number (e.g., [ID] = "101" or [ID] = 102), Power Query will fail. Ensure both sides of the operator are of the same type. Use the Transform tab to change the column type to Text or Whole Number before adding the custom column.

If the filter is not returning the expected rows, check for leading or trailing spaces in your data. A cell that looks like "London" but is actually "London " (with a space) will not match . To fix this, right-click the column header, select Transform, and choose Trim before applying your OR logic.

If you receive a "Token Literal expected" error, check your quotation marks. Text values must be enclosed in double quotes ("Value"). Single quotes are not recognized for text strings in M code.

Frequently Asked Questions

Can I use the OR operator in a filter without writing code?

Yes. By selecting multiple items in the filter dropdown menu of any column, Power Query automatically applies OR logic to those selections.

Is there a limit to how many OR conditions I can add?

There is no hard limit, but very long formulas can slow down the query refresh and become difficult to maintain. For more than 10-15 conditions, a Merge operation with a reference table is recommended.

Does the OR statement work across different columns?

Yes. In a Custom Column, you can reference any column in the table. For example, if [ColumnA] = 1 or [ColumnB] = 1 then "Match" else "No" is perfectly valid.

Why is my OR formula returning an error when I use it on a date column?

Date values cannot be written as simple text. You must use the #date(year, month, day) function. For example: .

Can I use OR logic with the "Contains" function?

Yes, but you must use Text.Contains. The formula would look like: if Text.Contains([Description], "Urgent") or Text.Contains([Description], "Immediate") then "Priority" else "Normal".