---
title: Build an Aggregation Custom Value Grouping on Two Fields
slug: segment/build-an-aggregation-custom-value-grouping-on-two-fields
createdAt: 2026-01-15T20:34:22.696Z
---

This page explains how to create an aggregation based on multiple fields, using as example counting the number of customers per **Gender&#x20;**&#x61;n&#x64;**&#x20;Country**.

To select a combination of multiple fields to create an aggregation upon, you first need to combine those fields as a new one you can later use when building the Aggregation.&#x20;

:::::WorkflowBlock
::::WorkflowBlockItem
1. Create a Step1 Selection with a Custom Value in the Target Definition that is using `CONCAT()` SQL function between *Country*  and *Gender* field.&#x20;

::Image[]{src="https://support.deselect.com/hc/article_attachments/29411361830417" size="70" width="1479" height="703" isUploading="false" darkWidth="1479" darkHeight="703" showCaption="false"}





::Image[]{src="https://support.deselect.com/hc/article_attachments/24200975205009" size="80" width="1246" height="826" isUploading="false" darkWidth="1246" darkHeight="826" showCaption="false"}





::Image[]{src="https://support.deselect.com/hc/article_attachments/24200975217041" size="80" width="1302" height="938" isUploading="false" darkWidth="1302" darkHeight="938" showCaption="false"}

2. Use this formula:

:::BlockQuote
CONCAT("DESelect\_DEMO\_Customers"."Country",'-',"DESelect\_DEMO\_Customers"."Gender")
:::

::Image[]{src="https://support.deselect.com/hc/article_attachments/24200967653905" size="80" width="1504" height="968" isUploading="false" darkWidth="1504" darkHeight="968" showCaption="false"}

3. As a result, you will have a Custom Value field added to the Target Data Extension, which has a unique value field, combining the fields that you need to use for your aggregation:

::Image[]{src="https://support.deselect.com/hc/article_attachments/24200975227281" size="80" width="1600" height="728" isUploading="false" darkWidth="1600" darkHeight="728" showCaption="false"}


::::

:::WorkflowBlockItem
1. Create a Step2 Selection, in which the Selection Criteria is the Target Data Extension of Step1.&#x20;

::Image[]{src="https://support.deselect.com/hc/article_attachments/29411348818321" size="80" width="2896" height="1388" isUploading="false" darkWidth="2896" darkHeight="1388" showCaption="false"}

2. In the Target Definition of Step2 Selection, and given our example “counting number of customers per Gender and Country” we need the following fields to be added to your Target Data Extension.
   - **Country**: (From the Selected Data Extension)
   - **Gender**: (From the Selected Data Extension)
   - **Count**: Custom Value, in which we are going to create our Aggregation, to count customers for each Country AND Gender.

::Image[]{src="https://support.deselect.com/hc/article_attachments/24200975247761" size="80" width="1306" height="944" isUploading="false" darkWidth="1306" darkHeight="944" showCaption="false"}
:::

:::WorkflowBlockItem
The result will be the Sum of *CustomerId* in the **DESelect\_Demo\_Customers** for each **Country-Gender** in **Step1.**

![](https://support.deselect.com/hc/article_attachments/29412029414545)

The preview will show the correct results, but they are duplicated (one row per *CustomerId*, even though the *CustomerId* column is not shown). Hence, you need to remove duplicates, for example, by making both **Country** an&#x64;**&#x20;Country-Gender** a primary key.

::Image[]{src="https://support.deselect.com/hc/article_attachments/29411991901073" size="80" width="2914" height="1500" isUploading="false" darkWidth="2914" darkHeight="1500" showCaption="false"}

Finally, the result will be what you're looking for:&#x20;

::Image[]{src="https://support.deselect.com/hc/article_attachments/29412029423505" size="80" width="2916" height="1508" isUploading="false" darkWidth="2916" darkHeight="1508" showCaption="false"}
:::
:::::

