Daily DAX : Day 427 BITLSHIFT

Power BI DAX Function: BITLSHIFT

Description

The BITLSHIFT function in Data Analysis Expressions (DAX) performs a bitwise left shift operation on an integer. It shifts the bits of the specified number to the left by the given number of positions, filling the low-order bits with zeros.

This is mathematically equivalent to multiplying the number by 2 raised to the power of the shift amount (for positive shifts).

Note: If the shift amount is negative, it performs a right shift instead (equivalent to BITRSHIFT with a positive amount).

Syntax

BITLSHIFT(, )

Parameters

  • Number: An integer expression (can be positive or negative).
  • Shift_Amount: An integer specifying the number of bits to shift (positive for left, negative for right).

Examples

ExpressionResultExplanation
BITLSHIFT(4, 2)164 in binary is 100; shifting left by 2: 10000 (16)
BITLSHIFT(10, 1)2010 (1010) → 10100 (20)
BITLSHIFT(8, 3)648 (1000) → 1000000 (64)
BITLSHIFT(16, -2)4Negative shift: right shift by 2 (equivalent to division by 4)

Use Cases

  • Efficient multiplication/division by powers of 2: Faster than using POWER(2, n) or repeated multiplication.
  • Bit flag manipulation: Setting specific bits in permission systems, status flags, or encoded integers (e.g., combining multiple boolean flags into one integer).
  • Data encoding/decoding: Packing/unpacking binary data or implementing custom algorithms requiring bit shifts.
  • Custom logical operations: Combined with other bitwise functions like BITAND, BITOR, BITXOR for advanced bit-level processing.

Important Notes

  • Be cautious of overflow/underflow for large shifts (|Shift_Amount| > 64 may cause unexpected results without errors).
  • Works with negative numbers using two's complement representation.
  • Useful in scenarios involving binary data, but rare in typical business intelligence reports.


Comments

Popular posts from this blog

Daily DAX : Day 131 SELECTEDMEASURE

Daily DAX : Day 446 INFO.CSDLMETADATA

Daily DAX : Day 453 ENDOFWEEK