> For the complete documentation index, see [llms.txt](https://docs.rasgoml.com/rasgo-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rasgoml.com/rasgo-docs/rasgo-0.1/all-transforms/metric.md).

# Metric

Calculate metric values given a metric definition

## Parameters

| Name                  | Type                | Description                                                                                                                                                                                                                                                                                                           | Is Optional |
| --------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| metrics               | comparison\_list    | List of input metrics/calculations to plot                                                                                                                                                                                                                                                                            |             |
| date\_settings        | timeseries\_options | Date settings containing the start and end dates as well as the time grain which will be used to create the datespine for metric calculation. Time grain options are ('day', 'week', 'month', 'year', 'quarter', and 'all') Example: { 'start\_date': '2021-12-01', 'end\_date': '2022-07-01', 'time\_grain': 'day' } |             |
| filters               | filter\_list        | Filter logic on one or more columns. Can choose between a simple comparison filter or advanced filter using free text.                                                                                                                                                                                                | True        |
| group\_by\_dimensions | dimension\_list     | Categorical column(s) by which to group the aggregated metrics. Including this argument will generate a new metric calculation for each distinct value in the group by column. If this column has more than 20 distinct values, the plot will not generate.                                                           | True        |

## Example

```python
ds = rasgo.get.dataset(id)

ds2 = ds.metric(
    metrics=[
      {
        "name": "AW_Sales_Revenue",
        "source_table": "RASGOLOCAL.PUBLIC.FQLUSMVCMIDATYSA",
        "type": "SUM",
        "target_expression": "SALESAMOUNT",
        "time_dimension": "ORDERDATE",
        "metric_dependencies": [],
      }
    ],
    filters=[],
    timeseries_options={
      "time_grain": "DAY",
      "start_date": {
        "direction": "past",
        "offset": 30,
        "datePart": "DAY",
        "type": "relative_date"
      },
      "end_date": {
        "direction": "past",
        "offset": 0,
        "datePart": "DAY",
        "type": "relative_date"
      }
    }
)
ds2.preview()

```

## Source Code

{% embed url="<https://github.com/rasgointelligence/RasgoTransforms/blob/main/rasgotransforms/rasgotransforms/transforms/metric/metric.sql>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.rasgoml.com/rasgo-docs/rasgo-0.1/all-transforms/metric.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
