Daily DAX : Day 374 BITAND

Power BI DAX BITAND Function

Description

The BITAND function in Power BI DAX performs a bitwise AND operation on two integer values. It compares each bit of the two numbers and returns a result where each bit is set to 1 only if both corresponding bits in the input numbers are 1.

Syntax

BITAND(<number1>, <number2>)
  • number1: The first integer value.
  • number2: The second integer value.

Return Value: An integer representing the result of the bitwise AND operation.

How It Works

The BITAND function converts the input numbers to their binary representation, performs a bitwise AND operation, and returns the result as an integer. For example:

  • BITAND(5, 3)
  • Binary of 5: 0101
  • Binary of 3: 0011
  • Bitwise AND: 0101 & 0011 = 0001
  • Result: 1 (in decimal)

Use Case

The BITAND function is useful in scenarios involving bitmasking or flag-based data analysis. For example, it can be used to check if specific permissions or settings (represented as bits) are enabled in a system.

Example Scenario: In a database, user permissions are stored as integers where each bit represents a specific permission (e.g., bit 1 = read, bit 2 = write). You can use BITAND to check if a user has specific permissions.

PermissionCheck = BITAND(UserPermissions, 2)

If UserPermissions = 6 (binary: 0110, meaning read and write permissions), then BITAND(6, 2) returns 2, confirming the write permission (bit 2) is set.

Example in DAX

Result = BITAND(10, 12)
  • Binary of 10: 1010
  • Binary of 12: 1100
  • Bitwise AND: 1010 & 1100 = 1000
  • Result: 8 (in decimal)

Notes

  • Both inputs must be integers; non-integer values are truncated to integers.
  • Negative numbers are supported and handled in two's complement form.
  • Commonly used in technical or low-level data scenarios, such as analyzing flags or binary states.

Comments

Popular posts from this blog

Daily DAX : Day 131 SELECTEDMEASURE

Daily DAX : Day 446 INFO.CSDLMETADATA

Daily DAX : Day 453 ENDOFWEEK