Smart Systems for Home

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

Power Query Number.BitwiseXor Function: How to Use It

· 5 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

The Number.BitwiseXor function in Power Query performs a bitwise XOR operation between two integers, returning a new integer where each bit is the result of XORing the corresponding bits of the two inputs. This is useful for comparing binary flags, toggling bits, or performing low-level data transformations. No external tools or add-ins are required — it works natively in Power Query within Excel, Power BI, or other Microsoft data platforms that support M language.

What You'll Need

  • Microsoft Excel 2016 or later, or Power BI Desktop
  • A table or column containing integer values to compare
  • Basic familiarity with Power Query Editor (accessed via Data > Get & Transform in Excel or Transform Data in Power BI)

Step-by-Step

  1. Open your Excel workbook or Power BI Desktop file and load the data you want to transform into Power Query. Click on the Transform Data button in the Data tab (Excel) or on your dataset in the Home tab (Power BI).
  2. In the Power Query Editor, identify the two columns containing integer values you wish to apply the XOR operation to. If they don’t exist, create them using Add Column > Custom Column and enter integer values manually or via other calculations.
  3. With the table selected, go to the Add Column tab and click Custom Column.
  4. In the Custom Column dialog box, type a name for the new column, such as BitwiseXorResult.
  5. In the formula box, enter: Number.BitwiseXor([Column1], [Column2]), replacing Column1 and Column2 with the actual names of your two integer columns. Ensure column names are enclosed in square brackets and match exactly, including capitalization.
  6. Click OK. Power Query will compute the XOR result for each row. For example, if Column1 has 5 (binary 101) and Column2 has 3 (binary 011), the result will be 6 (binary 110), because XOR returns 1 only where bits differ.
  7. Verify the results by manually checking a few rows. Use Windows Calculator in Programmer mode (View > Programmer) to convert decimal numbers to binary and confirm bit-by-bit XOR logic: 1 XOR 0 = 1, 0 XOR 1 = 1, 1 XOR 1 = 0, 0 XOR 0 = 0.
  8. Click Close & Load to apply the transformation and return the updated table to your worksheet or report.

Common Mistakes

  • Using non-integer values — Number.BitwiseXor only works with whole numbers. If your columns contain decimals, text, or nulls, the function will return an error. Use Number.RoundDown() or Number.From() to convert first.
  • Mismatched column names — If you type [column1] instead of [Column1], Power Query throws a Expression.Error. Column names are case-sensitive.
  • Applying to more than two columns — This function takes exactly two arguments. Trying to pass three or using a list will cause a syntax error.
  • Assuming it works on floating-point numbers — Even if a decimal appears whole (like 5.0), Power Query treats it as a number type, not an integer. Convert using Number.RoundDown() before applying XOR.

Tips

  • Use this function to toggle flags in bitmask fields — for example, if you have a status column where bit 1 = active, bit 2 = premium, and bit 4 = verified, XOR can flip a specific flag without affecting others.
  • Combine with Number.ToText() and Text.Middle() to examine individual bits. For instance, convert the result to binary string and check the nth character to see if a particular flag was toggled.
  • Test with small numbers first: 1 XOR 1 = 0, 1 XOR 0 = 1, 2 XOR 3 = 1. This helps validate your formula before applying to large datasets.
  • Remember: XOR is reversible. If A XOR B = C, then C XOR B = A. This can help you recover original values if needed.
  • For performance on large datasets, avoid applying XOR to columns with many nulls. Use Table.TransformColumns() with error handling to skip invalid rows.

Troubleshooting

  • Error: "We cannot apply operator XOR to types Number and Text" — One of your input columns contains text. Use Table.TransformColumns() to convert all inputs to number first: each Number.From(_).
  • Result is blank or null — One or both inputs are null. Wrap the formula in try Number.BitwiseXor([Col1], [Col2]) otherwise null to handle nulls gracefully, or filter out rows with nulls using Remove Rows > Remove Blank Rows.
  • Formula syntax error — Double-check spacing and bracketing. The correct form is Number.BitwiseXor(A, B) — no extra parentheses, no commas outside the argument list.
  • Unexpected results — Verify binary representation using a calculator. For example, 10 XOR 6 = 12? Convert 10 to 1010, 6 to 0110. XOR yields 1100 = 12. If your result doesn’t match, recheck column references.
  • Function not recognized — This function is available in Power Query M language from Excel 2016 onward and Power BI from 2018 onward. If you’re using an older version, update to a supported release.

Frequently Asked Questions

Can I use Number.BitwiseXor with negative numbers?

Yes. Power Query uses two’s complement representation for negative integers. The XOR operation works on the full 64-bit binary representation, so negative numbers are handled correctly. For example, -1 XOR 5 will return a result based on their binary patterns.

Does this function work on decimal numbers like 4.5?

No. Number.BitwiseXor requires integers. Passing 4.5 will result in an error. Convert decimals to integers first using Number.RoundDown(), Number.Round(), or Number.Truncate().

Can I apply XOR to more than two columns at once?

No. The function accepts exactly two arguments. To XOR three values, chain the operations: Number.BitwiseXor(Number.BitwiseXor(A, B), C).

Is Number.BitwiseXor available in Excel Online?

No. Power Query functions like Number.BitwiseXor are not supported in Excel Online. You must use the desktop version of Excel (Windows or Mac) to access this function.

What’s the difference between XOR and OR in this context?

XOR returns 1 only when bits differ (one is 1, the other is 0). OR returns 1 if either bit is 1. For example, 5 (101) OR 3 (011) = 7 (111), but 5 XOR 3 = 6 (110). XOR is useful for toggling, OR is for combining flags.

Will this function work if my data has leading zeros?

Leading zeros in decimal notation don’t affect the result. The function operates on the numeric value, not its string representation. So 005 and 5 are treated identically.