Skip to content

Commit ccd3dcc

Browse files
author
Charles Lariviere
committed
docs(README): add example of using a Metric in a Query aggregation
Signed-off-by: Charles Lariviere <charles@dribbble.com>
1 parent 0c33d3f commit ccd3dcc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ df = dataset.to_pandas()
124124
As shown above, the `Query` object allows you to easily compile MBQL from Python objects. Here is a
125125
more complete example:
126126
```python
127-
from metabase import Query, Sum, Average, Greater, GroupBy, BinOption, TemporalOption
127+
from metabase import Query, Sum, Average, Metric, Greater, GroupBy, BinOption, TemporalOption
128128

129129
query = Query(
130130
table_id=5,
131131
aggregations=[
132132
Sum(id=5), # Provide the ID for the Metabase field
133-
Average(id=5, name="Average of Price") # Optionally, you can provide a name
133+
Average(id=5, name="Average of Price"), # Optionally, you can provide a name
134+
Metric.get(5) # You can also provide your Metabase Metrics
134135
],
135136
filters=[
136137
Greater(id=1, value=5.5) # Filter for values of FieldID 1 greater than 5.5
@@ -147,7 +148,8 @@ print(query.compile())
147148
'source-table': 5,
148149
'aggregation': [
149150
['sum', ['field', 5, None]],
150-
['aggregation-options', ['avg', ['field', 5, None]], {'name': 'Average of Price', 'display-name': 'Average of Price'}]
151+
['aggregation-options', ['avg', ['field', 5, None]], {'name': 'Average of Price', 'display-name': 'Average of Price'}],
152+
["metric", 5]
151153
],
152154
'breakout': [
153155
['field', 4, None],

0 commit comments

Comments
 (0)