<commit_before>---
layout: docs
title: Aggregation
permalink: /docs/aggregate.html
---

To aggregate data in Vega-Lite, users can either use the `aggregate` property of an [encoding field definition](#encoding) or the `aggregate` transform inside the [`transform`](#transform) array. Aggregate summarized a table as one record for each group. To preserve the original table structure and instead add a new column with the aggregate values, use the [join aggregate](joinaggregate.html) transform.

<!--prettier-ignore-start-->
## Documentation Overview
{:.no_toc}

- TOC
{:toc}

<!--prettier-ignore-end-->

{:#encoding}

## Aggregate in Encoding Field Definition

<!-- TODO why aggregation -->

```js
// A Single View or a Layer Specification
{
  ...,
  "mark/layer": ...,
  "encoding": {
    "x": {<commit_msg>docs: fix grammar in aggregate docs (#6586)<commit_after>---
layout: docs
title: Aggregation
permalink: /docs/aggregate.html
---

To aggregate data in Vega-Lite, users can either use the `aggregate` property of an [encoding field definition](#encoding) or the `aggregate` transform inside the [`transform`](#transform) array. Aggregate summarizes a table as one record for each group. To preserve the original table structure and instead add a new column with the aggregate values, use the [join aggregate](joinaggregate.html) transform.

<!--prettier-ignore-start-->
## Documentation Overview
{:.no_toc}

- TOC
{:toc}

<!--prettier-ignore-end-->

{:#encoding}

## Aggregate in Encoding Field Definition

<!-- TODO why aggregation -->

```js
// A Single View or a Layer Specification
{
  ...,
  "mark/layer": ...,
  "encoding": {
    "x": {
{'fraction_non_alphanumeric': 0.13454545454545455, 'fraction_numerical': 0.0024242424242424242, 'mean_word_length': 4.048929663608563, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5503787', 'n_tokens_mistral': 514, 'n_tokens_neox': 467, 'n_words': 186}