---
title: "Report templating syntax"
description: "Look up the report template syntax shared by the Query and Proximity Analysis tools: aggregate variables, equations, and operators."
---

Query and Proximity Analysis reports use the same syntax. This page lists the syntax you can use in a report template — aggregate variables, equations, and the operators inside them. For the per-tool setup flow, see [How to set up the query tool](/docs/map-extensions/set-up-the-query-tool) and [How to set up proximity analysis](/docs/map-extensions/set-up-proximity-analysis).

## What a report is

A report is formatted text that renders after a viewer runs the Query or Proximity Analysis tool. The content can mix plain text, formatting (headings, lists, links), aggregate variables that read across the result set, and equations that combine those aggregates.

The diagram follows one report from the tool's results to the text the viewer reads.

<!-- diagram:report-data-flow -->
<svg class="dark:hidden" style="width: 100%; height: auto" viewBox="0 0 640 480" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="report-data-flow-inline-title report-data-flow-inline-desc">
  <title id="report-data-flow-inline-title">How a report is computed</title>
  <desc id="report-data-flow-inline-desc">Data flow: when a viewer runs Query or Proximity Analysis, the server takes the features the tool found, computes one aggregate for each field and function in the report, works out the equations from those aggregates, and sends the finished report to the viewer; a field with no values gives 0, and a missing field or a sum on a text field stops the report, while popup equations work on one feature at a time instead.</desc>
  <defs>
    <marker id="report-data-flow-inline-arrow" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto"><polygon points="0 0, 8 3, 0 6" fill="#525252"/></marker>
    <marker id="report-data-flow-inline-arrow-accent" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto"><polygon points="0 0, 8 3, 0 6" fill="#c4360c"/></marker>
  </defs>
  <rect width="100%" height="100%" fill="#f5f5f5"/>
  <rect x="20" y="96" width="296" height="280" rx="8" fill="rgba(23,23,23,0.04)" stroke="rgba(23,23,23,0.12)" stroke-width="1"/>
  <rect x="28" y="88" width="96" height="16" rx="2" fill="#f5f5f5"/><text x="76" y="100" fill="#525252" font-size="10" font-weight="600" letter-spacing="0.1em" font-family="inherit" text-anchor="middle">ON THE SERVER</text>
  <path d="M168 68 L168 118" fill="none" stroke="#525252" stroke-width="1.2" marker-end="url(#report-data-flow-inline-arrow)"/>
  <path d="M168 176 L168 206" fill="none" stroke="#525252" stroke-width="1.2" marker-end="url(#report-data-flow-inline-arrow)"/>
  <path d="M168 264 L168 294" fill="none" stroke="#525252" stroke-width="1.2" marker-end="url(#report-data-flow-inline-arrow)"/>
  <path d="M168 352 L168 402" fill="none" stroke="#c4360c" stroke-width="1.4" marker-end="url(#report-data-flow-inline-arrow-accent)"/>
  <path d="M296 236 L350 236" fill="none" stroke="#525252" stroke-width="1.2" stroke-dasharray="5,4" marker-end="url(#report-data-flow-inline-arrow)"/>
  <rect x="40" y="16" width="256" height="52" rx="20" fill="rgba(23,23,23,0.04)" stroke="rgba(23,23,23,0.32)" stroke-width="1"/><text x="168" y="39" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">A viewer runs the tool</text><text x="168" y="57" fill="#525252" font-size="12" font-family="inherit" text-anchor="middle">Query or Proximity Analysis</text>
  <rect x="40" y="120" width="256" height="56" rx="6" fill="#ffffff" stroke="#171717" stroke-width="1"/><text x="168" y="145" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Result set</text><text x="168" y="163" fill="#525252" font-size="12" font-family="inherit" text-anchor="middle">the features the tool found, not the layer</text>
  <rect x="40" y="208" width="256" height="56" rx="6" fill="#ffffff" stroke="#171717" stroke-width="1"/><text x="168" y="233" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Aggregates</text><text x="168" y="251" fill="#525252" font-size="12" font-family="inherit" text-anchor="middle">one per field:function, like gid:count</text>
  <rect x="40" y="296" width="256" height="56" rx="6" fill="#ffffff" stroke="#171717" stroke-width="1"/><text x="168" y="321" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Equations</text><text x="168" y="339" fill="#525252" font-size="12" font-family="inherit" text-anchor="middle">worked out from the aggregates only</text>
  <rect x="40" y="404" width="256" height="56" rx="20" fill="rgba(196,54,12,0.08)" stroke="#c4360c" stroke-width="1.4"/>
  <text x="168" y="429" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Rendered report</text>
  <text x="168" y="447" fill="#525252" font-size="12" font-family="inherit" text-anchor="middle">sent to the viewer</text>
  <rect x="352" y="188" width="272" height="98" rx="6" fill="rgba(23,23,23,0.04)" stroke="rgba(23,23,23,0.32)" stroke-width="1" stroke-dasharray="4,3"/><text x="368" y="212" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="start">Special cases</text><text x="368" y="234" fill="#525252" font-size="12" font-family="inherit" text-anchor="start">The field has no values: 0</text><text x="368" y="252" fill="#525252" font-size="12" font-family="inherit" text-anchor="start">The field isn’t in the layer: no report</text><text x="368" y="270" fill="#525252" font-size="12" font-family="inherit" text-anchor="start">sum, avg and others on text: no report</text>
  <rect x="352" y="404" width="272" height="56" rx="6" fill="rgba(23,23,23,0.04)" stroke="rgba(23,23,23,0.32)" stroke-width="1"/><text x="488" y="429" fill="#171717" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Popup equations, for contrast</text><text x="488" y="447" fill="#525252" font-size="12" font-family="inherit" text-anchor="middle">one feature’s values, no aggregates</text>
</svg>
<svg class="hidden dark:block" style="width: 100%; height: auto" viewBox="0 0 640 480" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="report-data-flow-inline-dark-title report-data-flow-inline-dark-desc">
  <title id="report-data-flow-inline-dark-title">How a report is computed</title>
  <desc id="report-data-flow-inline-dark-desc">Data flow: when a viewer runs Query or Proximity Analysis, the server takes the features the tool found, computes one aggregate for each field and function in the report, works out the equations from those aggregates, and sends the finished report to the viewer; a field with no values gives 0, and a missing field or a sum on a text field stops the report, while popup equations work on one feature at a time instead.</desc>
  <defs>
    <marker id="report-data-flow-inline-dark-arrow" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto"><polygon points="0 0, 8 3, 0 6" fill="#a3a3a3"/></marker>
    <marker id="report-data-flow-inline-dark-arrow-accent" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto"><polygon points="0 0, 8 3, 0 6" fill="#ff7a4d"/></marker>
  </defs>
  <rect width="100%" height="100%" fill="#141414"/>
  <rect x="20" y="96" width="296" height="280" rx="8" fill="rgba(242,242,242,0.05)" stroke="rgba(242,242,242,0.14)" stroke-width="1"/>
  <rect x="28" y="88" width="96" height="16" rx="2" fill="#141414"/><text x="76" y="100" fill="#a3a3a3" font-size="10" font-weight="600" letter-spacing="0.1em" font-family="inherit" text-anchor="middle">ON THE SERVER</text>
  <path d="M168 68 L168 118" fill="none" stroke="#a3a3a3" stroke-width="1.2" marker-end="url(#report-data-flow-inline-dark-arrow)"/>
  <path d="M168 176 L168 206" fill="none" stroke="#a3a3a3" stroke-width="1.2" marker-end="url(#report-data-flow-inline-dark-arrow)"/>
  <path d="M168 264 L168 294" fill="none" stroke="#a3a3a3" stroke-width="1.2" marker-end="url(#report-data-flow-inline-dark-arrow)"/>
  <path d="M168 352 L168 402" fill="none" stroke="#ff7a4d" stroke-width="1.4" marker-end="url(#report-data-flow-inline-dark-arrow-accent)"/>
  <path d="M296 236 L350 236" fill="none" stroke="#a3a3a3" stroke-width="1.2" stroke-dasharray="5,4" marker-end="url(#report-data-flow-inline-dark-arrow)"/>
  <rect x="40" y="16" width="256" height="52" rx="20" fill="rgba(242,242,242,0.05)" stroke="rgba(242,242,242,0.34)" stroke-width="1"/><text x="168" y="39" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">A viewer runs the tool</text><text x="168" y="57" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="middle">Query or Proximity Analysis</text>
  <rect x="40" y="120" width="256" height="56" rx="6" fill="#1c1c1c" stroke="#f2f2f2" stroke-width="1"/><text x="168" y="145" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Result set</text><text x="168" y="163" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="middle">the features the tool found, not the layer</text>
  <rect x="40" y="208" width="256" height="56" rx="6" fill="#1c1c1c" stroke="#f2f2f2" stroke-width="1"/><text x="168" y="233" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Aggregates</text><text x="168" y="251" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="middle">one per field:function, like gid:count</text>
  <rect x="40" y="296" width="256" height="56" rx="6" fill="#1c1c1c" stroke="#f2f2f2" stroke-width="1"/><text x="168" y="321" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Equations</text><text x="168" y="339" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="middle">worked out from the aggregates only</text>
  <rect x="40" y="404" width="256" height="56" rx="20" fill="rgba(255,122,77,0.10)" stroke="#ff7a4d" stroke-width="1.4"/>
  <text x="168" y="429" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Rendered report</text>
  <text x="168" y="447" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="middle">sent to the viewer</text>
  <rect x="352" y="188" width="272" height="98" rx="6" fill="rgba(242,242,242,0.05)" stroke="rgba(242,242,242,0.34)" stroke-width="1" stroke-dasharray="4,3"/><text x="368" y="212" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="start">Special cases</text><text x="368" y="234" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="start">The field has no values: 0</text><text x="368" y="252" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="start">The field isn’t in the layer: no report</text><text x="368" y="270" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="start">sum, avg and others on text: no report</text>
  <rect x="352" y="404" width="272" height="56" rx="6" fill="rgba(242,242,242,0.05)" stroke="rgba(242,242,242,0.34)" stroke-width="1"/><text x="488" y="429" fill="#f2f2f2" font-size="14" font-weight="600" font-family="inherit" text-anchor="middle">Popup equations, for contrast</text><text x="488" y="447" fill="#a3a3a3" font-size="12" font-family="inherit" text-anchor="middle">one feature’s values, no aggregates</text>
</svg>
<!-- /diagram:report-data-flow -->

Both tools use the same editor and syntax — anything in this page works in either tool's report.

## Aggregate variables

|         |                                                          |
| ------- | -------------------------------------------------------- |
| Syntax  | `{field_name:function}` |
| Where   | Anywhere in the report body |

Insert with the variable button in the toolbar, or type the syntax directly.

<img src="/_assets/map-extensions/report-templating-reference--editor.png" alt="Report content editor of a query with its toolbar and three aggregate variables, {height:sum}, {levels:avg}, and {gid:count}, under the heading Building summary; below it, Report preview shows the same text and placeholders run together on one line, with no heading style" width="1600" height="960" />

Aggregates operate on the **result set** — the features returned by the tool's spatial selection and attribute filters — not the entire layer. Reports do not support single-feature variables; every field reference must include an aggregate function.

Available functions:
| Function | Returns |
| --- | --- |
| `sum` | Sum of every result feature's value for the attribute |
| `avg` | Mean across every result feature |
| `count` | Count of **distinct non-null values** across the result set |
| `min` | Minimum value |
| `max` | Maximum value |
| `median` | The median (50th percentile) |

For example, in a report on a parcels layer: `{land_value:sum}` returns the total `land_value` across the parcels in the result set; `{lot_size:median}` returns the median lot size.

### `count` quirk

`count` returns the number of **distinct** values, not the number of features. `{gid:count}` returns the number of features (because `gid` is unique per row), but `{state:count}` returns the number of distinct states in the result set, not the row count. Use a uniquely-valued field (typically `gid`) when you want a feature count.

## Equations

|         |                                                          |
| ------- | -------------------------------------------------------- |
| Insert with | `Insert equation` in the report editor toolbar |
| Where   | Inline in the report, alongside aggregate variables and plain text |

Click `Insert equation` and type an expression to compute a value from one or more aggregate variables.

Operators in the expression:

- `+` — addition
- `-` — subtraction
- `*` — multiplication
- `/` — division
- `(...)` — grouping

For example, the equation `{land_value:sum} / {lot_size:sum}` computes the layer-wide average land value per unit of lot size across the result set.

Reports calculate equations the same way as popups. Every operator, function, and formatting method in [Calculator formula syntax](/docs/configuring-popups/calculator-formula-reference) also works in a report equation, such as `{land_value:sum}.toLocaleString()`.

In the report editor, the equation editor preview has no sample values. It shows `No sample value for {field:function}`, such as `No sample value for {land_value:sum}`.

Moving from v3? In v3, you typed equations into the report as `#{...}#`. In v4, typed `#{...}#` stays as plain text and does not calculate. Click `Insert equation` and type only the expression.

## Mixing variables, equations, and prose

A typical report layout:
```text
**Selected parcels:** {gid:count}
**Total land value:** ${land_value:sum}
**Median lot size:** {lot_size:median} m²
**Average value per m²:** $<equation>
```
For `<equation>`, click `Insert equation` and type `{land_value:sum} / {lot_size:sum}`.

## Missing values

Aggregates default to `0` when no values are present for the field across the result set.

A report fails when a placeholder names a field that the layer doesn't have, or uses `sum`, `avg`, `min`, `max`, or `median` on a text field. Only `count` works on text fields. The Query tool then shows an error instead of results, and Proximity Analysis shows its results with no report.

In an equation, such a placeholder shows `Missing:` and its name, such as `Missing: land_vlaue:sum`. An equation that cannot calculate, such as one that divides by zero, shows `Error`.

## Differences from popup equations

The Calculator popup and the Custom popup also insert equations with `Insert equation`, but they evaluate **per feature**, not per result set. Consequently:

- **Aggregate variables (`{field:function}`) are not available in popups** — they only work here, in Query and Proximity Analysis reports.
- **Single-feature variables (`{field_name}`) are not available in reports** — popups use them; reports require an aggregate.

See [Calculator formula syntax](/docs/configuring-popups/calculator-formula-reference) for the per-feature equation reference.

## Related

- [How to set up the query tool](/docs/map-extensions/set-up-the-query-tool) — the per-tool setup that includes the report-template field.
- [How to set up proximity analysis](/docs/map-extensions/set-up-proximity-analysis) — same model for proximity reports.
- [Calculator formula syntax](/docs/configuring-popups/calculator-formula-reference) — per-feature equation syntax for popups.
