# Aggregated expressions

## Create an aggregated expression

Aggregations in expressions that have transaction filter selections, containing relative date rule filters, will have those translated to the appropriate date selection based upon the **Today** date.

To illustrate the use of aggregations in expressions in the Segmentation tool, a **recency aggregation** will be used that contains a **relative date rule**.

In this example, the objective is to view **the Last Continent that a person had been to at each of the reporting points set in the Segmentation tool**.

1. Open an **Expression** window and, using **Selector Functions**, enter the **DescOf(**.
2. Click on the **Add Aggregation** button and then switch to the new **Frequency(Communications)** tab.
3. Change the **Type** box to **Recency**.
4. Change the **Transactional Table** to **Bookings**.
5. Drag the **Booking Date** variable on to the **Order records by** drop box.
6. Change the **From** box to show **Latest to Earliest**.
7. Drag the **Continent-CC** (on Holidays this variable is associated with Destination and has been generated via the Combine Categories wizard) onto the **Pick the** drop box.
8. Change the **Name** to **Last Continent Before Today**.

To create the transaction filter that includes a relative date rule:

1. Drag **Booking Date** onto the workspace and select the **Custom Rule** option.
2. Select **The Earliest Date** radio button in the **From** section, and the **Today** radio button in the **To** section.
3. Click OK.

   This will result in the **Today** date being translated by the Segmentation tool to whatever reporting points have been set, and will look at the transactions from that point back to **The Earliest Date**.
4. Rename the selection **Before Today** and drag it on to the transactions filter drop box.
5. Click on the **Expression** tab and complete the expression by adding a closed bracket **)**.
6. Rename the **Expression** as **Last Continent Visited**.
7. Click the **Build** button to see a preview of the results.
8. Use a **Data Grid** to validate the results.

## Use in segmentation

To use the above in the **Segmentation** tool, a series of selections need to be created, representing the Last Continent Visited.

1. Drag the **Last Continent Visited** expression on to a blank selection window.
2. Enter the value **Europe** in the right hand panel.
3. Rename the selection **Last Europe** and save in the **Private** folder.
4. Repeat the above for **Asia**, **Africa**, **Americas** and **Australasia**.

   These selections can now be analysed in the Segmentation tool.
5. Open the **Segmentation** tool and drag on the 5 selections previously created.
6. Set the **Reporting Points** for **every 1<sup>st</sup> January from 2015 onwards**.
7. Click on the **Time Report** tab and click the **Build** button.

In the screen shot below a grid is displayed with 4 reporting points. The highlighted cell represents those people whose last continent visited before 01/01/2016 was Asia.

You can drag the cell on to the workspace and use a **Data Grid** to validate the results

In the screen shot above, the people illustrated meet the criteria of visiting Asia as the last continent before 01/01/2016, even though the first and third person went on to visit different continents subsequently.
