Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Number.BitwiseOr: How to Use It

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Power Query's Number.BitwiseOr function returns the bitwise OR of two numbers: it compares them bit by bit and sets each result bit to 1 if either input has a 1 in that position. This is useful for combining flag values, permission masks, or status codes stored as integers. You do not need any add-ins or special setup — the function is built into Power Query in Excel, Power BI, and other Microsoft products that host Power Query. The steps below show how to call it in a custom column or a blank query, with practical examples and the mistakes that most often trip people up.

What You'll Need

  • A version of Excel, Power BI Desktop, or another tool that includes the Power Query Editor. The function is part of the standard M library, so no extra installation is required.
  • Two whole numbers (integers) to combine. Power Query will convert decimal values to integers before the bitwise comparison, so decide in advance whether that rounding is acceptable for your data.
  • Basic familiarity with opening the Power Query Editor and adding a custom column or a blank query. If you have never used Power Query, start with a simple table first.

Step-by-Step

  1. Open the Power Query Editor. In Excel, select your data and choose Data > From Table/Range. In Power BI Desktop, choose Home > Transform data. The exact label can differ slightly by version, device, or region, but the entry point is always the Power Query Editor.
  2. Decide where the result should go. If you want a new column in an existing table, use Add Column > Custom Column. If you just want to test the function, use Home > New Source > Blank Query and work in the formula bar.
  3. Write the function call. The syntax is Number.BitwiseOr(number1, number2). Both arguments are required and must be numbers. For example, Number.BitwiseOr(5, 3) returns 7, because 5 is binary 101 and 3 is binary 011, and the OR of those is 111, which is 7.
  4. Use it in a custom column. In the Custom Column dialog, give the column a name and enter a formula such as Number.BitwiseOr([FlagsA], [FlagsB]), replacing the field names with your actual column names. Field names are case-sensitive and must be enclosed in square brackets.
  5. Check the data type. After adding the column, confirm the new column is typed as Whole Number. If Power Query shows it as Any or Decimal, change the type using the icon in the column header or Transform > Data Type. A wrong type can make later steps behave unexpectedly.
  6. Handle nulls before calling the function. If either input can be null, wrap the call so nulls do not break the step. A common pattern is if [FlagsA] = null or [FlagsB] = null then null else Number.BitwiseOr([FlagsA], [FlagsB]). This keeps the column clean and avoids errors during refresh.
  7. Apply and load. Choose Home > Close & Load (or Close & Apply in Power BI) to send the result back to your worksheet or data model. Refresh the query later to confirm the calculation still works with new data.

Common Mistakes

  • Passing text instead of numbers. If a column contains values like "5" as text, the function may fail or return an error. Convert the column to Whole Number first, or use Number.From inside the formula.
  • Expecting decimal arithmetic. Bitwise OR works on the binary representation of integers. Number.BitwiseOr(1.5, 2) is not a meaningful decimal operation; Power Query converts the values to integers first, which can surprise you.
  • Forgetting null handling. A null in either argument produces a null or an error depending on context. Decide explicitly what should happen when data is missing.
  • Using the wrong column names. In a custom column, column references must match the exact header text and be wrapped in square brackets. Renaming a column later will break the formula until you update it.
  • Assuming the result is a flag you can read directly. The OR result is a combined number, not a list of flags. To check whether a specific bit is set, combine it with Number.BitwiseAnd and compare to the bit value.

Tips

  • Test the function in a blank query first. Type = Number.BitwiseOr(5, 3) in the formula bar and press Enter; the result should show 7. This confirms the function is available in your version.
  • Use bitwise OR when you need to merge permission or status flags. For example, if 1 means "read" and 2 means "write", Number.BitwiseOr(1, 2) returns 3, meaning both permissions are present.
  • Keep a small reference table of bit values in your workbook so colleagues can decode the combined numbers without guessing.
  • Combine with Number.BitwiseAnd to test individual bits: Number.BitwiseAnd(result, 2) = 2 tells you whether the "write" bit is set.
  • Document the formula in a comment or a nearby note. Bitwise logic is not obvious to everyone who opens the query later.

Troubleshooting

If the function returns an error, check the data type of both input columns first. Text values and nulls are the most common causes. Convert the columns to Whole Number and add null handling as shown above. If the formula bar shows a red error underline, confirm the function name is spelled exactly Number.BitwiseOr with the correct capitalization; Power Query function names are case-sensitive.

If the custom column step fails after a refresh, open the step and inspect the formula. A renamed source column will cause a field-not-found error; update the reference to the new name. If the query is slow, check whether the bitwise step is applied before or after filtering — applying it to fewer rows is faster.

If the result looks wrong, verify the inputs are integers and that you have not mixed up OR with AND. OR sets a bit when either input has it; AND sets a bit only when both do. A quick manual check: convert both numbers to binary and compare them position by position.

If the function is not recognized at all, your version of Power Query may be older than the function. Update your Excel or Power BI Desktop to a current version through the official update channel. Do not install unofficial add-ins to work around it.

Frequently Asked Questions

What does Number.BitwiseOr return?

It returns a whole number representing the bitwise OR of the two inputs. Each bit in the result is 1 if either input has a 1 in that position.

Can I use more than two numbers?

The function takes exactly two arguments. To combine more than two values, nest calls, for example Number.BitwiseOr(Number.BitwiseOr(a, b), c).

Does it work with negative numbers?

Bitwise operations on negative integers depend on how the number is represented internally. Avoid relying on negative inputs unless you have tested the specific behavior in your version and documented it.

What happens if I pass a decimal?

Power Query converts the value to an integer before the bitwise comparison. The conversion can change the result, so round or truncate deliberately before calling the function.

Is Number.BitwiseOr available in Excel Power Query?

Yes, it is part of the standard Power Query function library in current versions of Excel and Power BI Desktop. Older versions may not include it; update through official channels if it is missing.

How do I check whether a specific bit is set?

Use Number.BitwiseAnd with the bit value and compare the result to that value. If the result equals the bit value, the bit is set.