How to add timestamp from SQL query to grafana alert body?

I am in Grafana V11, and I’m really struggling to get the time column from the query into the alert body. I have read through numerous topics and gone through the documentation, I have been at this for 2 days tinkering on and cannot get it to work.

I have a simple SQL query returning 2 columns, time and value for the past hour:

I have 2 expressions that get the last value and trigger the alert when above a threshold:

Literally all I want to do is have the alert message like this example:
Meter crossed threshold at 2025-07-30 13:02:44.607.

I have a contact point set up, and I have tried using labels and annotations but cannot seem to get the timestamp to come through. Can anyone help me do this, feel like it’s definitely possible, I just haven’t cracked it yet.

Thanks in advance.

This one is a bit tricky. The situation is that your SQL query returns rows of timestamp + value. Grafana Alerting interprets this as time series data, like:

Series 1 = [{ts1, v1}, {ts2, v2}, {ts3, v3} …]

If you instead cast the timestamp as text, Grafana will treat the result as tabular data. That changes how the alerting processes it (see screenshots for comparison).

More details on how table data works in alerting are this example on tabular data.

When handled as tabular data, ts becomes a label, so you can reference it in your notification template like:

{{ range .Alerts -}}
Meter crossed threshold at {{ .Labels.ts_text }} {{ end -}}

Hope this helps!