# Team Price Groups (⚠️ EOL)
:::warning{title="Soon to be deprecated"}

This table is being deprecated and will be removed. Please migrate to [`price_groups`](/docs/price_groups) as soon as possible.

**Deprecation timeline:**
- **Week 4, 2027 (week of 25 January):** this model gets a `DEPRECATED__` prefix. Queries using the current name will stop working — repoint to the new name to keep using it.
- **Week 8, 2027 (week of 22 February):** this view is removed for good.

The replacement [`price_groups`](/docs/price_groups) table includes both team-owned and operator-owned price groups. To get the same results as this table, filter on `owner_type = 'Team'`.

:::

Contains team pricing group configurations and their application metrics across charge points,  sites, and team members. Provides comprehensive counts and aggregations for both total and  non-deleted entities to support pricing strategy analysis and billing operations. Filters  data to include only teams associated with the main operator.

**SQL:** `team_price_groups`

## Schema

| Column Name                          | Data Type     | Description                                                                                                             |
|:-------------------------------------|:--------------|:------------------------------------------------------------------------------------------------------------------------|
| **Primary ID**                       |               |                                                                                                                         |
| id                                   | INTEGER       | Primary key                                                                                                             |
| **Other IDs**                        |               |                                                                                                                         |
| team_id                              | INTEGER       | Foreign key reference to the team associated with this price group                                                      |
| operator_id                          | INTEGER       | Foreign key reference to the operator managing this price group                                                         |
| external_id                          | VARCHAR       | External system identifier for the price group used for integration purposes                                            |
| **Timestamps**                       |               |                                                                                                                         |
| created_at                           | TIMESTAMP_NTZ | Timestamp when the price group record was originally created                                                            |
| updated_at                           | TIMESTAMP_NTZ | Timestamp when the price group record was last modified                                                                 |
| deleted_at                           | TIMESTAMP_NTZ | Timestamp when the price group was soft deleted, null if still active                                                   |
| **Filters**                          |               |                                                                                                                         |
| is_main_operator_match               | BOOLEAN       | Indicates whether this price group belongs to the main operator (true) or a different operator (false)                  |
| **Attributes**                       |               |                                                                                                                         |
| type                                 | VARCHAR       | Classification or category of the price group configuration                                                             |
| name                                 | VARCHAR       | Human-readable name assigned to the price group for identification                                                      |
| team_member_count                    | INTEGER       | Number of team members currently associated with this price group                                                       |
| charge_point_count                   | INTEGER       | Number of charge points currently associated with this price group                                                      |
| applied_to_charge_points_total       | INTEGER       | Total count of charge points where this price group is applied, including deleted entities                              |
| applied_to_sites_total               | INTEGER       | Total count of sites where this price group is applied, including deleted entities                                      |
| applied_to_team_members_total        | INTEGER       | Total count of team members where this price group is applied, including deleted entities                               |
| applied_to_charge_points_non_deleted | INTEGER       | Count of active charge points where this price group is applied, excluding soft-deleted entities                        |
| applied_to_sites_non_deleted         | INTEGER       | Count of active sites where this price group is applied, excluding soft-deleted entities                                |
| applied_to_team_members_non_deleted  | INTEGER       | Count of active team members where this price group is applied, excluding soft-deleted entities                         |
| charge_point_count_total             | INTEGER       | Aggregate count of all charge points associated with this price group, including deleted entities                       |
| site_count_total                     | INTEGER       | Aggregate count of all sites associated with this price group, including deleted entities                               |
| team_member_count_total              | INTEGER       | Aggregate count of all team members associated with this price group, including deleted entities                        |
| charge_point_count_non_deleted       | INTEGER       | Aggregate count of active charge points associated with this price group, excluding soft-deleted entities               |
| site_count_non_deleted               | INTEGER       | Aggregate count of active sites associated with this price group, excluding soft-deleted entities                       |
| team_member_count_non_deleted        | INTEGER       | Aggregate count of active team members associated with this price group, excluding soft-deleted entities                |
| legacy_count_valid_rows              | INTEGER       | Number of valid data rows used in calculations for this price group record (used to match with legacy version of model) |

## Changes from last Version
### Summary

- Filter Changes: Removed implicit deleted filter; now exposes deleted records with deleted_at column
- Aggregation Fields: Adds extensive aggregation columns tracking applied/count metrics for charge points, sites, and team members (both total and non-deleted)

### Added columns (16)
- operator_id
- deleted_at
- applied_to_charge_points_total
- applied_to_sites_total
- applied_to_team_members_total
- applied_to_charge_points_non_deleted
- applied_to_sites_non_deleted
- applied_to_team_members_non_deleted
- charge_point_count_total
- site_count_total
- team_member_count_total
- charge_point_count_non_deleted
- site_count_non_deleted
- team_member_count_non_deleted
- count_valid_rows
- is_main_operator_match

### Removed columns (0)

### Renamed columns (3)
- team_price_group_id -> id
- team_price_group_type -> type
- team_price_group_name -> name

## Inclusion Criteria
* the `team_id` must exist in the operator's `teams.id`

## Data flow
| Upstream tables | Downstream tables             |
|:----------------|:------------------------------|
| `teams` | `charge_member_costs` |

## Alignment
### Monta API
- Aligns with Monta API [get/price-groups](https://developer.monta.com/api/v1/price-groups/get) endpoint 
- The API requires a teamID be passed
- The API excludes rows where `deleted_at is not null`
