TO_ACTIVITY_BITS()
All functions > BUSINESS > TO_ACTIVITY_BITS()
Returns the activity bits for the given array of activity dates and date reference.
Signatures
Returns: Bit-packed representation of activity over last 56 days
TO_ACTIVITY_BITS(activity: ARRAY<DATE>, date_ref: DATE, [active_before: BOOLEAN]) → BIGINT sql
| Parameter | Type | Required | Description |
|---|---|---|---|
activity | ARRAY<DATE> | Yes | Array of dates when user was active |
date_ref | DATE | Yes | Reference date to encode activity relative to |
active_before | BOOLEAN | No | Optional flag if user was active before tracking period |
Notes
- Encodes up to 56 days of activity into a single 64-bit integer
- Each bit represents one day (1 = active, 0 = inactive)
- Bit 0 (LSB) = reference date, Bit 1 = day before, etc.
- Bit 56 (MSB) = flag for activity before 56-day window
- Efficient storage for user activity tracking
- Use with IS_ACTIVE, COUNT_ACTIVE, ACTIVITY_STATUS functions
- Inverse of FROM_ACTIVITY_BITS
Examples
FeatureQL
SELECT
f1 := TO_ACTIVITY_BITS(ARRAY[DATE '2025-01-20', DATE '2025-01-19'], DATE '2025-01-20'), -- Two recent active days packed into a BIGINT
f2 := TO_ACTIVITY_BITS(ARRAY[DATE '2025-01-20'], DATE '2025-01-20', TRUE) -- Optional active-before flag sets the high guard bit
;Result
| f1 BIGINT | f2 BIGINT |
|---|---|
| 3 | 72057594037927937 |
On this page