FROM and SHOW
Every query starts with FROM and the object to report on, followed by SHOW and the numbers you want.
FROM dealsSHOW count, value, won_valueFROM <object>FROM takes one object: deals, contacts, invoices, orders, subscriptions and so on. The Objects page lists them all, with what each one holds and whether it can be combined with others.
SHOW <metric>[, <metric> ...]SHOW takes one or more metrics, separated by commas.
| Form | Example | Result |
|---|---|---|
| A metric of the object | SHOW count, won_value |
The catalog metric |
| A related object’s metric | SHOW deals.won_value |
The metric of the linked records |
| Renamed | SHOW won_value AS revenue |
The column is called revenue |
| Scaled | SHOW won_value * 12 AS ARR |
The metric times a number |
| Math | SHOW won_value / won_count AS avg_won |
A calculated metric |
| A function of a field | SHOW avg(amount), sum(mrr) |
See Functions |
| Filtered | SHOW count FILTER (WHERE stage = "MQL") |
The metric over only the matching records |
Combine metrics with + - * / and parentheses:
FROM dealsSHOW won_value * 12 AS ARR, won_value / won_count AS avg_won, won_count * 100 / count AS win_pctGROUP BY ownerDividing by zero shows an empty value. In tables, a calculated rate is totaled from its parts, so the totals row stays correct. Money stays money: won_value / won_count is shown as currency, while won_value / value is a plain number.
Related metrics
Section titled “Related metrics”When the object can be combined, show the metrics of linked records next to its own:
FROM contactsSHOW count, deals.count, deals.won_value, orders.totalGROUP BY sourceEach object keeps its own permissions and data visibility, and its own date: deals.won_value counts the deals won in the period, and a time grouping such as GROUP BY month puts each deal in the month it was won, while count puts each contact in the month it was created.
Filtered metrics
Section titled “Filtered metrics”WHERE applies to every metric in the query. To count only some records for one metric, add FILTER (WHERE …) after it:
FROM contactsSHOW count AS "Marketing contacts", count FILTER (WHERE stage = "MQL") AS MQL, deals.won_count FILTER (WHERE stage = "Closed Paid") AS "Closed Paid"WHERE source = "Marketing Generated"TIMESERIES monthEach month shows the marketing contacts created that month, the ones of them now in the MQL stage, and the Closed Paid deals of marketing contacts won that month.
- The conditions use the metric’s own object:
count FILTER (WHERE stage = "MQL")filters contacts,deals.won_count FILTER (WHERE stage = "Closed Paid")filters deals. To narrow every metric, useWHERE. - A filtered metric keeps its meaning and its date:
won_countstill counts only won deals, by the date they were won. - It works in math, such as an MQL rate:
count FILTER (WHERE stage = "MQL") * 100 / count AS mql_rate. - Name it with
ASto sort, chart or check it inHAVING. Without a name, the column is labelled with the metric and the options it keeps, such as “Contacts (MQL)”. - It works on objects that can be combined, and not in a
COHORTreport.
Examples
Section titled “Examples”-- Revenue and order count this monthFROM ordersSHOW total, countDURING this_month-- Average won deal per ownerFROM dealsSHOW won_value / won_count AS avg_wonGROUP BY ownerDURING this_yearON won_at