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.
Read more about MetricReportInput
.
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.
Read more about MetricReportConnection
.
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
- GraphQL Variables
- JSON Response
query MetricReportExample($input: MetricReportInput!) {
metricReport(input: $input) {
headers
rows
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
}
}
{
"input": {
"timeRange": {
"start": "2023-08-03T00:00:00Z",
"stop": "2023-08-08T00:00:00Z"
},
"dimensions": [
{
"columnName": "restaurant_name"
},
{
"columnName": "taco_name"
}
],
"metrics": [
{
"uniqueName": "Revenue"
},
{
"uniqueName": "Taco Sales Count"
}
],
"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.