# Var Groups (Features)

`var_groups` define and organize features for entities and cohorts, and they consist of `input_vars` and `entity_vars`. 

You can `var_groups` in the [`profiles.yaml`]({{< ref "profiles/dev-docs/profiles-yaml/" >}}) file:

```yaml
var_groups:
    name: var_groups_name
    entity_key: entity_name
    time_grain: day
    vars:
        - input_var:
          <input-var-config>
        - entity_var:
          <entity-var-config>
```

| Key | Description |
| :---------- | :------ |
| `name` | Name of the `var_groups`. |
| `entity_key` | `entity` for the defined vars. |
| [`time_grain`]({{< ref "profiles/concepts/timegrains.md" >}}) | Controls how often features in this group are computed. This parameter accepts the following values: `tick`, `10minutes`, `hour`, `day`, `week`, `month`, `year`. <br /><br />See [Timegrains]({{< ref "profiles/concepts/timegrains.md" >}}) for details. |
| `vars` | Definition of entity and input vars. |
| [`entity_var`]({{< ref "profiles/dev-docs/profiles-yaml/var-groups/entity-var.md" >}}) | Entity variable configuration. |
| [`input_var`]({{< ref "profiles/dev-docs/profiles-yaml/var-groups/input-var.md" >}}) | Input variable configuration. See warning below. |

{{< warning >}}
**Input vars scan all input data on every run, which can be expensive for large datasets.** 

Consider using [`entity_var` with Incremental Features]({{< ref "profiles/dev-docs/incremental-features/make-features-incremental.md" >}}) or [Incremental SQL Models]({{< ref "profiles/dev-docs/incremental-features/incremental-sql-models/" >}}) instead for better performance.

Use `input_var` only when you need to add a calculated column to the input table itself (for example, window functions that must be computed before entity-level aggregation).
{{< /warning >}}

## Example

```yaml
var_groups:
    name: user_var_group
    entity_key: user
    time_grain: day  # Features in this group are computed daily
    vars:
        - input_var:
          name: page_count
          select: count(distinct url)
          from: inputs/rsPages
          window:
            partition_by:
              - profile_id
              - date
          description: Add column to rsPages SQL model to get a page count per date
        - entity_var:
          name: web_dates_visited_365_days
          select: array_agg(distinct object_construct('date', date, 'page_count',{{pages_orderby_table.page_count}}))
          from: inputs/rsPages
          description: rolling 365 days array of json objects with the UTC timestamps the user visited the website along with the number of pages visited per date stamp
        - entity_var:
          name: first_order_date
          select: min(order_date)
          from: inputs/orders
          description: First order date
        - entity_var:
          name: last_order_date
          select: max(order_date)
          from: inputs/orders
          is_feature: false
        - entity_var:
          name: days_since_la`st_order
          select: "date_diff(CURRENT_DATE(), date({{user.last_order_date}}), day)"
          description: Days since user last completed an order
```

