Metric Report
The Metric Report query allows you to build comprehensive reports by grouping one or more Metrics by common dimensions. These reports can be visualized as tables with sortable columns and built-in pagination.
Usage​
When you need to display tabular data that includes multiple Metrics grouped by specific dimensions, the Metric Report is a suitable choice. It can be used in conjunction with Time Series to provide valuable insights within in-product analytics. Metric Reports are typically rendered as tables like so:
restaurant_name | taco_name | Revenue | Taco Sales Count |
---|---|---|---|
El Buen Sabor | Carne Asada | 2754 | 789 |
El Buen Sabor | Al Pastor | 2251 | 681 |
El Buen Sabor | Fish | 2105 | 623 |
Sabor Mexicano | Shrimp | 2031 | 598 |
Taco Fiesta | Barbacoa | 1987 | 564 |
Sabor Mexicano | Chorizo | 1890 | 530 |
Taco Fiesta | Pollo | 1782 | 482 |
El Buen Sabor | Veggie | 1542 | 377 |
Sabor Mexicano | Breakfast | 1523 | 412 |
Taco Fiesta | Carnitas | 1345 | 321 |
See below for an example of how data like this can be retrieved using Metric Report.
Arguments​
You will pass a MetricReportInput
when querying. The most important
arguments when querying a metric report are
- The
timeRange
to query over. - The
dimensions
to break down by. Supports a maximum of 10 dimensions. You must supply at least one dimension. - The
metrics
you wish to display. Supports a maximum of 10 Metrics. You must supply at least one Metric. orderByColumn
- which column, specified by number starting at 1 inclusive of dimensions and metrics you wish to order by.first
refers to the number of rows to return.
Field | Type | Required | Description |
---|---|---|---|
timeRange | TimeRangeInput | No | The time range for calculating the Metric Report. |
timeZone | String | No | The time zone to use. Dates and times are always returned in UTC, but setting the time zone influences relative time ranges and granularities. You can set this to "America/Los_Angeles", "Europe/Berlin", or any other value in the IANA time zone database. Defaults to "UTC". |
dimensions | array of MetricReportDimensionInput | Yes | One or many dimensions to group the Metric values by. Typically, dimensions in a report are what you want to compare and rank. |
metrics | array of MetricReportMetricInput | Yes | One or more Metrics to include in the Metric Report. These will be broken down by |
filterSql | String | No | The Query Filters to apply when building the Metric Report, in the form of SQL. These can be used to filter out rows. |
orderByColumn | Int | No | The index of the column to order the Metric Report by. The index is 1-based and defaults to the first Metric column. In other words, by default, reports are ordered by the first Metric; however, you can order by the second Metric, third Metric, etc., by overriding the |
first | Int | No | The number of rows to be returned when paging forward. It can be a number between 1 and 1,000. |
after | String | No | The cursor to use when paging forward. |
last | Int | No | The number of rows to be returned when paging forward. It can be a number between 1 and 1,000. |
before | String | No | The cursor to use when paging backward. |
Returns​
The query returns an array of headers
and an array of rows
inside a
MetricReportConnection
:
- The
headers
array is an array of header names for the report table: the first header names correspond to the dimensions you passed to thedimensions
argument when querying the report; the final header name is always "value". - The
rows
array is an array of rows for the metric report table. Each row is itself an array of columns. The column order matches theheaders
order.
The final column of each row is a number wrapped in a string. Using a string ensures we can support values greater than 32-bits in the GraphQL API.
Field | Type | Nullable | Description |
---|---|---|---|
pageInfo | PageInfo | No | The report connection's page info. |
edges | array of MetricReportEdge | No | The report connection's edges. |
nodes | array of MetricReportNode | No | The report connection's nodes. |
headers | array of String | No | An ordered array of display names for your dimensions and Metrics, as defined in the report input. Use this to display your table's header. |
rows | array of String | No | An ordered array of rows. Each row contains dimension and Metric values, as defined in the report input. Use these to display the rows of your table. |
query | QueryInfo | No | The Query statistics and metadata. |
Example​
Suppose we have a Data Pool syncing from a table of restaurant sales data. The data might look like the following:
Note: this data has essentially the same format as the TacoSoft data we used in our Quickstart.
Before proceeding with the example query below, you will need to create two Sum Metrics:
- A Sum Metric for the "total price" column, which could be named "Revenue". This will represent the total revenue of all tacos sold.
- A Sum Metric for the "quantity" column, which could be named "Taco Sales Count". This will represent the total number of tacos sold.
What are the top performing restaurants and best selling tacos?​
In this example, we aim to identify the top-performing restaurants and best-selling tacos by grouping sales data by the attributes restaurant_name
and taco_name
. The query below groups the "Revenue" Metric and the "Taco Sales Count" Metric by these two attributes. By specifying "orderByColumn": 1
in the input, the results are ordered by the first column, which corresponds to the restaurant name. Additionally, by setting "first": 10
in the input, the query retrieves only the first 10 rows.
- GraphQL Query
- JSON Response
Query:
query MetricReportExample($input: MetricReportInput!) {
metricReport(input: $input) {
headers
rows
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
}
}
Variables:
{
"input": {
"timeRange": {
"relative": "LAST_N_DAYS",
"n": 30
},
"dimensions": [
{
"columnName": "restaurant_name"
},
{
"columnName": "taco_name"
}
],
"metrics": [
{
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
}
},
{
"metric": {
"countDistinct": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"dimension": {
"columnName": "order_id"
}
}
}
}
],
"orderByColumn": 1,
"first": 10
}
}
{
"data": {
"metricReport": {
"headers": [
"restaurant_name",
"taco_name",
"Revenue",
"Taco Sales Count"
],
"rows": [
["El Buen Sabor", "Carne Asada", "2754", "789"],
["El Buen Sabor", "Al Pastor", "2251", "681"],
["El Buen Sabor", "Fish", "2105", "623"],
["Sabor Mexicano", "Shrimp", "2031", "598"],
["Taco Fiesta", "Barbacoa", "1987", "564"],
["Sabor Mexicano", "Chorizo", "1890", "530"],
["Taco Fiesta", "Pollo", "1782", "482"],
["El Buen Sabor", "Veggie", "1542", "377"],
["Sabor Mexicano", "Breakfast", "1523", "412"],
["Taco Fiesta", "Carnitas", "1345", "321"]
],
"pageInfo": {
"startCursor": "eyJvZmZzZXQiOjB9",
"endCursor": "eyJvZmZzZXQiOjl9",
"hasNextPage": true,
"hasPreviousPage": false
}
}
}
}
You can replicate this query on GraphQL Explorer by logging in here.
You can learn more about how to structure a Metric Report query here.