# Cross Table Sum

Links columns in two tables. This column value is the sum of the values in a column in another table.

This generator does not provide a preview. The sums are not computed until the other table is generated.

For example, a **Customers** table contains a **Total\_Sales** column. The **Transactions** table uses a foreign key **Customer\_ID** column to identify the customer who made the transaction, and an **Amount** column that contains the amount of the sale. The **Customer\_ID** value in the **Transactions** table is a value from the **ID** primary key column in the **Customers** table.

You assign the Cross Table Sum generator to the **Total\_Sales** column. In the generator configuration, you indicate that the value is the sum of the **Amount** values for the **Customer\_ID** value that matches the primary key **ID** value for the current row.

For the **Customers** row for ID `123`, the **Total\_Sales** column contains the sum of the **Amount** column for **Transactions** rows where **Customer\_ID** is `123`.

## Characteristics <a href="#cross-table-sum-characteristics" id="cross-table-sum-characteristics"></a>

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top"><strong>Consistency</strong></td><td valign="top">No, cannot be made consistent.</td></tr><tr><td valign="top"><strong>Linking</strong></td><td valign="top">No, cannot be linked.</td></tr><tr><td valign="top"><strong>Differential privacy</strong></td><td valign="top">No</td></tr><tr><td valign="top"><strong>Data-free</strong></td><td valign="top">No</td></tr><tr><td valign="top"><strong>Allowed for primary keys</strong></td><td valign="top">No</td></tr><tr><td valign="top"><strong>Allowed for unique columns</strong></td><td valign="top">No</td></tr><tr><td valign="top"><strong>Uses format-preserving encryption (FPE)</strong></td><td valign="top">No</td></tr><tr><td valign="top"><strong>Privacy ranking</strong></td><td valign="top">3</td></tr><tr><td valign="top"><strong>Generator ID (for the API)</strong></td><td valign="top"><a href="../../../api/quick-start-guide/tonic-api-generator-assignment/generator-api-reference/generator-api-ref-cross-table-sum"><code>CrossTableAggregateGenerator</code></a></td></tr></tbody></table>

## How to configure <a href="#cross-table-sum-configure" id="cross-table-sum-configure"></a>

To configure the generator:

1. From the **Foreign Table** dropdown list, select the table that contains the column for which to sum the values.
2. From the **Foreign Key** dropdown list, select the foreign key.\
   \
   The foreign key identifies the row from the current table that is referred to in the foreign table.
3. From the **Sum Over** dropdown list, select the column for which to sum the values.
4. From the **Primary Key** dropdown list, select the primary key for the current table.
5. If [Structural data encryption](https://docs.tonic.ai/app/generation/generators-assign-config/generators-data-encryption-config) is enabled, then to use it for this column, in the advanced options section, toggle **Use data encryption process** to the on position.
