---
title: Bucket longtask durations into performance ranges
description: Group RUM `longtask` durations into Green, Orange, Red, and Purple ranges with `case_lessthan` and count events per range.
url: https://coralogix.com/docs/dataprime/cookbook/bucket_longtask/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-11-02'
---

# Bucket longtask durations into performance ranges

## Problem / Use case

You want to monitor Real User Monitoring (RUM) `longtask` durations and categorize them into performance buckets (e.g., fast, moderate, slow) to track client-side performance issues by severity.

## Query

```
source default/rum.events

| filter longtask_context.duration > 0

| groupby case_lessthan {

   longtask_context.duration:num,

   100 -> 'Green (0-100)',

   200 -> 'Orange (101-200)',

   300 -> 'Red (201-300)',

   _   -> 'Purple (301 - *)'

 } as Range

 agg count() as count
```

Note

This query targets the `default/rum.events` dataset, where RUM fields have no `cx_rum.` prefix. If your account still writes RUM data to `default/logs`, use `source logs` and write the field as `cx_rum.longtask_context.duration`. See [Querying RUM logs](https://coralogix.com/docs/user-guides/rum/query-rum-logs.md).

## Expected output

| Range             | count  |
| ----------------- | ------ |
| Green (0-100)     | 143973 |
| Red (201-300)     | 14961  |
| Orange (101-200)  | 36519  |
| Purple (301 - \*) | 6230   |

## Variations

* Adjust bucket thresholds based on your UX performance criteria.
* Swap `count()` for `distinct_count(session_id)` to measure impact per user session.

## TL;DR

Use `case_lessthan` to bucket `longtask` durations into performance ranges for easier trend analysis and alerting. Think of it as your RUM-grade Energon scanner.
