# Aggregating data

### Overview

<figure><img src="/files/YFJwmyV0SkE6wXNhlvZV" alt="aggregate widget" width="203"><figcaption><p>aggregate widget</p></figcaption></figure>

### Examples

{% hint style="warning" %}
Warning

Before you start!

My dataset is containing my turnover per Quarter for each year.
{% endhint %}

<figure><img src="/files/kZAplb6lnLVQsvUzJXpJ" alt="dataset"><figcaption><p>dataset</p></figcaption></figure>

#### Ex1: Group by

I want to display the evolution of my turnover per year. I need to group all my values per year using the Aggregate step : Group By operation:

* Group by allows you to perform different types of operation on your KPIs : you can sum them up or get their average for example !

Your YouPrep™ step should look like this:

<figure><img src="/files/Q7r0EqlEULqzViTBvvy5" alt="YouPrep™ step"><figcaption><p>YouPrep™ step</p></figcaption></figure>

Here you go ;)

<figure><img src="/files/KB58w8WRH4DektmldflW" alt="YouPrep step"><figcaption><p>YouPrep step</p></figcaption></figure>

#### Ex2: Hierarchical rollup

My data might only contains data at the lowest level. The hierarchical rollup operation will allow you to aggregate data at each hierarchical level and stack the aggregated data of every level, based on hierarchical columns (e.g. city < subcountry < counrtry ). This step is really helpful to give your dataset a hierarchical structure that Toucan could interpret properly for its charts (ex leaderboard drill, waterfall drill… or even hierarchical view selector).

> 📝 Perfect operation to set a hierarchy with only the children value.

Before you start! You will often have to display various levels of aggregations on your screens. For ewample, my dataset contains the main cities worldwide. We can find different level: names of the city, subcountry and country. Thanks to the hierarchical rollup operation, we are going to create a hierarchy between these three columns.

```
![keep column](image14.png)

I would like to have the number of main cities by subcountries and countries. By adding a hierarchical rollup step, the output data structure stacks the data of every level of the hierarchy, specifying for every row the label, level and parent in dedicated columns.
Your YouPrep step should look like this:
![rollup operation](image10.png)

Now I can add a filter to be able to have the ranking of the main city at the three levels:
  - Ranking of the countries containing the most “main cities”
  - Ranking of the sub countries containing the most “main cities”
  - Ranking of the main cities

![rollup operation2](image11.png)
```

Ex3: Get unique

> 📝 You can use this step to get the unique values from a column or unique groups of values from a combination of several columns.

<figure><img src="/files/96445Nhi09fcpJHqYtGn" alt="get unique1" width="375"><figcaption><p>get unique1</p></figcaption></figure>

Get unique groups/values in columns: you can select one or several columns that will be combined to constitute unique groups of values.

<figure><img src="/files/peXnl3WzonUhDu7cfqDh" alt="get unique2"><figcaption><p>get unique2</p></figcaption></figure>

Tadaaaa 🎉

<figure><img src="/files/TLMmHotaHmHm1kioDJmd" alt="get unique3"><figcaption><p>get unique3</p></figcaption></figure>

Do not hesitate to read the [weaverbird](https://weaverbird.toucantoco.dev/docs/general-principles/) documentation if you need any further informations on YouPrep!


---

# Agent Instructions: 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:

```
GET https://docs-v3.toucantoco.com/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/aggregate/aggregating-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
