Grafana Transformations

Transformations process query results inside Grafana before they reach the panel. You reshape, filter, merge, and calculate data without changing your original data source or writing complex queries. Transformations run entirely in the browser, making them fast and non-destructive.

The Spreadsheet Analogy

Think of raw query data as a spreadsheet with rows and columns. Transformations are like Excel formulas and filters you apply on top. You sort a column, remove unwanted rows, rename headers, or merge two sheets. The original data stays untouched — you only change what the panel displays.

Query Result (raw)          After Transformation
─────────────────────       ─────────────────────────────
instance  │ value           instance  │ CPU %  │ Status
server-01 │ 0.42            server-01 │ 42%    │ OK
server-02 │ 0.91            server-02 │ 91%    │ CRITICAL
server-03 │ 0.12            server-03 │ 12%    │ OK

Accessing Transformations

Open the panel editor. Click the Transform tab at the top of the query section (next to the Query tab). Click Add transformation to select from the list of available transformations. You chain multiple transformations — they run in the order listed, with each one receiving the output of the previous.

Core Transformations

Filter by Name

Removes columns (fields) from the result that you do not need. If your query returns ten columns but the panel only needs three, use Filter by Name to hide the rest.

Before: Time | instance | cpu | memory | disk | network
After:  Time | instance | cpu

Rename by Regex

Renames columns using a regular expression pattern. This is useful when your data source returns technical column names and you want to display friendly names.

Pattern: node_cpu_usage_percent
Replace: CPU Usage (%)

Organize Fields

Rename, reorder, and hide individual columns in one transformation. Drag handles let you reorder columns visually. Toggle the visibility eye icon to show or hide each column.

Reduce

Collapses a time series into a single value per series. You choose which calculation to apply: Last (most recent value), Mean (average), Max, Min, Sum, or Count. Use Reduce to feed time-series data into a Stat or Gauge panel.

Time Series Data:
  12:00 → 42
  12:01 → 47
  12:02 → 38

After Reduce (Max):
  → 47

Filter Data by Values

Removes rows where a field value does not meet a condition. For example, keep only rows where CPU usage exceeds 80%. This produces a table showing only the overloaded servers.

Filter: value > 80

Before:
  server-01 → 42   (removed)
  server-02 → 91   (kept)
  server-03 → 12   (removed)

After:
  server-02 → 91

Sort By

Sorts table rows by a specified field in ascending or descending order. Descending sort on a "CPU Usage" column puts the most loaded server at the top — ideal for a "hot servers" table.

Limit

Keeps only the first N rows after any sorting is applied. Combine Sort By + Limit to create a "Top 5 Busiest Servers" panel.

Sort by CPU descending → Limit to 5 rows
Result: Top 5 servers by CPU usage

Add Field from Calculation

Creates a new column by performing a calculation on existing columns. You can add, subtract, multiply, or divide two columns. You can also apply window functions like Moving Average or Cumulative Sum.

Columns: total_bytes | header_bytes
New field: body_bytes = total_bytes - header_bytes

Convert Field Type

Changes the data type of a column. For example, convert a string timestamp to a proper time type, or convert a string "1" to a number for calculations.

Group By

Groups rows by a field and aggregates others. Similar to SQL GROUP BY. For example, group by "status_code" and sum the "request_count" column to get total requests per status code.

Before:                     After (Group by status, Sum count):
method  status  count       status  total_count
GET     200     500         200     700
POST    200     200         404     150
GET     404     100         500     50
POST    404     50
GET     500     50

Merge

Combines the results of multiple queries into a single table. When two queries return data with a common field (like "instance"), Merge joins them side by side into one row per instance.

Query A result:           Query B result:
instance  │ cpu           instance  │ memory
server-01 │ 42            server-01 │ 68
server-02 │ 91            server-02 │ 85

After Merge:
instance  │ cpu │ memory
server-01 │ 42  │ 68
server-02 │ 91  │ 85

Join by Field (Outer Join)

Similar to Merge but gives more control over how two tables are joined. Use it when two queries share a time column and you want to align them row by row.

Concatenate Fields

Creates a new text column by joining values from two or more columns with a separator. For example, concatenate "region" and "instance" with a dash to get "US-East-server-01" as a single label.

Chaining Transformations

You apply transformations in sequence. The output of one feeds into the next. Build complex data shapes step by step.

Step 1: Merge (combine CPU and Memory queries)
    ↓
Step 2: Add Field from Calculation (compute Memory Usage %)
    ↓
Step 3: Filter by Values (keep only rows where CPU > 70)
    ↓
Step 4: Sort by (CPU descending)
    ↓
Step 5: Limit (top 10 rows)
    ↓
Panel shows: Top 10 high-CPU servers with memory usage

Debug Tip: Inspect Between Steps

After adding a transformation, check the panel preview to see the effect. If the data looks wrong, temporarily disable transformations by clicking the eye icon next to each one to find which step introduced the problem.

Leave a Comment

Your email address will not be published. Required fields are marked *