You are currently viewing How to use Power BI DAX Bitwise Operations?
Power BI DAX Bitwise Operations

How to use Power BI DAX Bitwise Operations?

In this post, we will discuss the Power BI DAX bitwise operations “BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT“.

Power BI DAX Bitwise Operations
Power BI DAX Bitwise Operations

What is Dax in Power BI?

Data Analysis Expressions (DAX) is a formula expression language explicitly designed for the management of data models, the DAX formulas include functions and operators that can be used to create formulas and expressions in Analysis Services, Power BI, and Power Pivot in Excel.

DAX in Power BI includes a library of over 200 functions, operators, that are used by report designers to perform data analysis and calculations.

Power BI DAX Bitwise Operations

This section focus on the new Bitwise DAX function that was introduced in November 2021.

The Bitwise DAX function helps you to returns a bitwise of two numbers through using the below additional functions:

  1. BITAND.
  2. BITOR
  3. BITXOR
  4. BITLSHIFT
  5. BITRSHIFT

Power BI Bitwise AND (BITAND)

DAX BITAND function is one of the logical functions in DAX that returns a bitwise AND of two numbers.

Power BI Bitwise AND (BITAND) Syntax

BITAND(<number1>, <number2>)

Note: If the value is not an integer, it is truncated.

Power BI Bitwise AND (BITAND) Examples

Example1:

In this example, you will notice that the BITAND DAX function takes two numbers as integer and convert each number to a binary number then perform AND logical operation then results in a new binary number (1001) that will be converted to an integer value (1001)=9.

BITAND(11,13) the output will be 9
Power BI BITOR DAX function, how it works
Power BI BITOR DAX function, how it works

Example2:

In this example, consider you have a table with two columns (Number1, and Number2), and each column holds an integer value as shown below:

Power BI BITAND DAX function
Power BI BITAND DAX function

So in this case, you will be forced to use the BITWISE keyword to can get the column value, and then use the BITAND DAX function as below:

BITAND(BITWISE[Number1],BITWISE[Number2])

Power BI Bitwise OR (BITOR)

DAX BITOR function returns a bitwise OR of two numbers.

Note: If the value is not an integer, it is truncated.

Power BI BITOR Syntax

BITOR(<number1>, <number2>)

Example1

Again, as we earlier explained, the BITOR DAX function takes two numbers as integer and converts each number to binary number then perform OR logical operation then results in a new binary number (1111) that will be converted to an integer value (1111)=15.

BITOR(13, 11) the output will be 15
 Power BI Bitwise OR (BITOR)
Power BI BITOR DAX function

Example2

In this example, consider you have a table with two columns (Number1, and Number2), and each column holds an integer value as shown below:

Power BI BITOR DAX function output
Power BI BITOR DAX function output

In this case, you will be forced to use the BITWISE keyword to can get the column value, and then use the BITOR DAX function as below:

BITOR = BITOR(BITWISE[Number1],BITWISE[Number2])

Power BI Bitwise XOR (BITXOR)

DAX BITXOR function returns a bitwise XOR of two numbers.

Note: If the value is not an integer, the function will not work and truncate.

Power BI BITXOR Syntax

BITXOR(<number1>, <number2>)

Example1

the BITXOR DAX function takes two numbers as integer and converts each number to binary number then perform XOR logical operation then results in a new binary number (0110) that will be converted to an integer value (0110)=6.

BITXOR(13, 11) the output will be 6
Power BI Bitwise XOR
Power BI BITXOR DAX function

Example2

BITXOR= BITXOR(BITWISE[Number1],BITWISE[Number2])

Output

Power BI BITXOR DAX function output
Power BI BITXOR DAX function output

Power BI Bitwise LSHIFT(BITLSHIFT)

DAX BITLSHIFT function return a number shifted left by the specified number of bits.

Power BI BITLSHIFT Syntax

BITLSHIFT(<Number>, <Shift_Amount>) 

If Shift_Amount is negative, it will shift in the opposite direction.

Example1

BITLSHIFT(4, 2) the output will be 16

Example2

BITLSHIFT= BITLSHIFT(BITWISE[Number1],2)
Power BI BITLSHIFT Operations
Power BI BITLSHIFT Operations

Example3

BITLSHIFT(128, -1) the output will be 64

Power BI Bitwise RSHIFT(BITRSHIFT)

DAX BITRSHIFT function returns a number shifted right by the specified number of bits.

Power BI BITRSHIFT Syntax

BITRSHIFT(<Number>, <Shift_Amount>) 

If Shift_Amount is negative, it will shift in the opposite direction.

Example1

BITRSHIFT(11, 13) the output will be 2

Example2

BITRSHIFT= BITRSHIFT(BITWISE[Number1],2)
Power BI LSHIFT DAX function
Power BI LSHIFT DAX function

Conclusion

In conclusion, we have learned How to use the Bitwise DAX function in Power BI by exploring the below related DAX functions

  • BITAND.
  • BITOR
  • BITXOR
  • BITLSHIFT
  • BITRSHIFT
Download

You can download the Bitwise DAX function examples file at Power BI DAX Bitwise Operations, and don’t forget to follow Power BI Repo to get more PIBX files samples with complex DAX formulas.

See Also
Join us
Need Help
  • Have a related question? Please ask it at deBUG.to Community.

Mohamed El-Qassas

I'm Microsoft MVP, SharePoint StackExchange Moderator, Microsoft QnA Moderator, C# Corner MVP, Microsoft TechNet Wiki Judge, and Senior Technical Consultant with +12 years of experience in SharePoint, Project Server and Power Platform.