Grafana Guide: Transformations and Expressions

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-11 against Grafana 13.3.x.

What you build

You add two panels to the dashboard Bookshelf (guides). The first one, a table called Route summary, runs two Prometheus queries, the request rate and the p95 latency of every route, and a chain of transformations joins the results, renames the columns, adds a rate per minute, drops the quiet routes, groups the rows and reduces them to a single summary row. The second one, a time series called Requests per minute, uses expressions to multiply a query by 60, to reduce it to a number and to run a SQL statement on it.

Finished dashboard Bookshelf (guides) in view mode with two new panels: the table Route summary with one row holding the highest request rate, the highest rate per minute and the highest p95 latency, and the time series Requests per minute that draws the rates of the status codes 200 and 404 times 60

Before you start

  • Start the Grafana profile of the hands-on lab and wait about a minute:

    cd lab
    docker compose --profile grafana up -d
  • Open http://localhost:3000, sign in as admin with the password admin, and click Skip when Grafana 13.3 asks you to update the default password.

  • Do the earlier guides in this series, at least Create a dashboard and the first panel, which creates the dashboard Bookshelf (guides) in the folder Guides, and Tables, which builds a first table.

  • The data source Prometheus is provisioned by the lab and is the default data source. The load generator runs in its default mode and gives the queries traffic to draw. SQL expressions are available in the free Grafana 13.3 image.

  • The guide was checked on Grafana Enterprise 13.3.0 (the free image, no licence key). Editing dashboards needs the Editor or Admin role of the organization; admin has it.

  • The figures are drawings of the Grafana 13.3 user interface, not screenshots, so small details can differ from your screen. A highlighted box with a number marks the control of the step with the same number.

Steps

A transformation changes the data after the data source returned it and before the visualization draws it; an expression is calculated on the server from the results of queries. Both live in the panel editor: transformations under the bottom tab Transformations, expressions under the button Expression below the queries. The settings of each transformation card are drawn from the names Grafana gives them; if a label differs on your screen, pick the closest entry.

The screen maps of the dashboard in edit mode and of the panel editor are in the guide Create a dashboard and the first panel; come back to them when a control is not where a figure shows it.

Add a table panel with two queries

  1. In the left navigation, click Dashboards, then open the folder Guides and the dashboard Bookshelf (guides).

  2. Click Edit.

    Dashboard Bookshelf (guides) in view mode with the navigation docked: callout 1 marks the Dashboards item of the navigation and callout 2 marks the Edit button of the toolbar
  3. Click Add in the toolbar.

  4. In the Add pane of the right sidebar, click the Panel tile.

    Dashboard Bookshelf (guides) in edit mode with the Add pane of the right sidebar open: callout 3 marks the Add button of the toolbar and callout 4 marks the Panel tile of the Add pane
  5. In the Panel pane that replaces the Add pane, click Edit visualization.

  6. At the bottom of the panel editor, check that Data source shows Prometheus. In query A, click Code in the Builder / Code switch.

  7. Click inside the query editor first, so that it has the focus, then type the request rate by route:

    sum by (uri) (rate(http_server_requests_seconds_count{application="bookshelf"}[1m]))
  8. Open the Options line of query A and set Format to Table.

  9. In the same line, set Type to Instant.

    Panel editor on the Queries tab: callout 6 marks the Code option of query A, the query that sums the request rate by uri is typed in the editor (callout 7), and the opened Options row shows Format set to Table (callout 8) and Type set to Instant (callout 9)
  10. Click Add query.

  11. In query B, click Code.

  12. Click inside the editor of query B and type the p95 latency by route on one line (the editor may wrap it):

    histogram_quantile(0.95, sum by (le, uri) (rate(http_server_requests_seconds_bucket{application="bookshelf"}[5m])))
  13. In the Options line of query B, set Format to Table.

  14. Set Type to Instant.

  15. Click Run queries.

    Panel editor with two queries: Add query is marked by callout 10, query B has its Code option (callout 11) and the p95 latency query typed in the editor (callout 12), its Options row shows Format Table (callout 13) and Type Instant (callout 14), and Run queries is marked by callout 15
  16. In the right column, click the All visualizations tab.

  17. Click Table ("Supports many column styles").

  18. In the options pane, under Panel options, type Route summary in Title.

Join the queries and tidy the columns

  1. At the bottom of the editor, click the Transformations tab.

  2. Click Add transformation.

    Panel editor on the Transformations tab with the table titled Route summary: the tab is marked by callout 19 and the empty state offers the Add transformation button, marked by callout 20
  3. In the Add another transformation drawer, click Join by field.

  4. In the card, choose uri as the field to join by. The table now holds one row per route with the two value columns, named after their queries, Value #A for the rate and Value #B for the latency.

    The Join by field transformation: its Field select holds uri (callout 22); the preview shows one table with the columns Time, uri, Value #A with the request rates and Value #B with the p95 latencies
  5. Below the card, click the button that adds another transformation and choose Organize fields by name.

  6. Switch off every Time field, so that the time columns disappear.

  7. Type Route as the new name of uri.

  8. Type Requests per second as the new name of Value #A.

  9. Type p95 latency (s) as the new name of Value #B.

    The Organize fields by name transformation: the Time field is switched off (callout 24), uri is renamed to Route (callout 25), Value #A to Requests per second (callout 26) and Value #B to p95 latency (s) (callout 27); the preview shows a table with three columns

Calculate, filter and debug

  1. Add the transformation Add field from calculation.

  2. Set Mode to the binary operation.

  3. Build the operation Requests per second * 60: choose the field Requests per second, the operator * and type 60.

  4. Type Requests per minute in Alias.

    The Add field from calculation transformation: the Mode is the binary operation (callout 29), the operands read Requests per second, the operator * and the value 60 (callout 30) and the Alias is Requests per minute (callout 31); the preview shows the new column Requests per minute
  5. Add the transformation Filter data by values.

  6. Add a condition and choose the field Requests per second.

  7. Choose the operator Greater.

  8. Type 1.05 as the value. The route /api/loans, which gets about one request per second, leaves the table.

    The Filter data by values transformation with one condition: the field Requests per second (callout 33), the operator Greater (callout 34) and the value 1.05 (callout 35); the preview lists three routes, because /api/loans with 1.0 requests per second is gone
  9. Click the debug icon in the header of the Filter data by values card. The card shows the data that goes in and the data that comes out, side by side. Click the icon again to close the view.

    The Filter data by values card with its debug view open: the debug icon in the card header is marked by callout 36, below it the Input table lists four routes and the Output table lists three

Summarise with Group by and Reduce

In this lab every route appears once, so Group by only renames the columns here; it matters when a query returns several rows for a route, for example when you add status to the sum by clause.

  1. Add the transformation Group by.

  2. Set the field Route to Group by.

  3. Set the field Requests per second to Calculate.

  4. Choose the calculation Total for it.

  5. Set Requests per minute to Calculate with Total, and p95 latency (s) to Calculate with Max.

    The Group by transformation: the field Route is set to Group by (callout 38), Requests per second is set to Calculate (callout 39) with the calculation Total (callout 40), and the other two fields are set the same way; the preview shows three routes with the totals and the maximum latency
  6. Add the transformation Reduce.

  7. Set Mode to Reduce fields.

  8. In Calculations, choose Max. The table shrinks to one row.

    The Reduce transformation: its Mode is Reduce fields (callout 43) and its Calculations select holds Max (callout 44); the preview shrinks to one row with the highest request rate, the highest rate per minute and the highest p95 latency

Use expressions in a time series panel

Expressions calculate on time series, so the second panel uses a range query.

  1. Click Back in the header of the editor. The panel stays on the dashboard, which is still in edit mode.

  2. Add another panel and open its editor, as in steps 3 to 5.

  3. In query A, click Code.

  4. Click inside the editor and type the request rate by status:

    sum by (status) (rate(http_server_requests_seconds_count{application="bookshelf"}[1m]))
  5. Click Run queries.

  6. Under Suggestions, click Time series.

  7. Click Expression below the queries and choose Math.

  8. In the expression, type:

    $A * 60
  9. Click Expression again and choose Reduce.

  10. Set Function to Last.

  11. Set Input to A.

  12. Set Mode to Drop Non-numeric Values.

    Panel editor of a time series panel titled Requests per minute: the Expression button under query A is marked by callout 51, the Math expression C holds the text $A * 60 (callout 52), and the Reduce expression D has Function Last (callout 54), Input A (callout 55) and Mode Drop Non-numeric Values (callout 56)
  13. Click Expression a third time and choose SQL.

  14. In the editor of the SQL expression, type a statement that reads query A as a table named A:

    SELECT * FROM A LIMIT 5
    Panel editor with the Expression button marked by callout 57 and a new SQL expression E whose editor holds the statement SELECT * FROM A LIMIT 5, marked by callout 58
  15. In the options pane, under Panel options, type Requests per minute in Title.

  16. Click Save in the header of the editor.

  17. In the Save dashboard drawer, click Save.

  18. Click Back.

  19. Click Exit edit.

  20. If Grafana 13.3.0 shows the dialog Unsaved changes, click Save, and click Save again in the drawer that opens.

Check the result

Open Dashboards → Guides → Bookshelf (guides). The table Route summary shows one row with the highest request rate, the highest rate per minute (60 times the rate) and the highest p95 latency of the routes that get more than one request per second. The time series Requests per minute draws the status codes 200 and 404 at 60 times the per-second rate.

To see the table react, make the Bookshelf service slow, wait a minute and press Refresh; the maximum of p95 latency (s) grows:

curl -X POST localhost:8090/mode/slow

Restore normal traffic afterwards:

curl -X POST localhost:8090/mode/normal

To inspect the results of the Reduce and SQL expressions, open the panel Requests per minute in the editor and switch on Table view in its header.

Variations

  • Disable a transformation temporarily instead of deleting it, to see how the table looked before it, or open the debug view of any card.

  • Replace Filter data by values with Sort by or Limit to keep only the busiest routes.

  • Use the expressions Resample and Threshold, which the alerting guides need, in the same way: click Expression and choose the type.

What can go wrong

Symptom Cause Fix

The join gives an empty table or a single query’s columns

One query still has the format Time series, or a query was not run again after the change.

Set Format to Table and Type to Instant in both queries and click Run queries.

The latency column is empty

The query for p95 has no data because the one-minute window of rate was too short, or the load generator is stopped.

Keep the range [5m] of query B, wait a few minutes after starting the lab, and check curl localhost:8090/ for the mode.

The rename in Organize fields by name does not show

The rename field was typed for a field that a join or another card renamed.

Check the debug view of the previous card for the field names it passes on.

The Math expression returns no data

The query A of this panel is hidden or formatted as a table.

Use the range query of step 48 with the default Time series format and click Run queries.

The SQL expression reports an error

The table name does not match the query’s reference id.

Name the query in the FROM clause exactly as the query, A.

Clean up

Keep the panels if you want to try the variations. To remove a panel, open the dashboard in edit mode, select it, click Delete in the Panel pane of the right sidebar and save the dashboard. The later guides in this series do not depend on them.

Where to go next