> For the complete documentation index, see [llms.txt](https://docs.fabricplan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fabricplan.com/powertable-sheets/how-tos/adding-columns-overview/add-visual-column/relation-column.md).

# Relation Column

A relation column creates a one-to-many relationship between records in two tables. It links a record in a parent (master) table to one or more related records in a child (details) table, enabling you to organize and manage related data across tables. This is called a **master-detail relationship**.

This feature is used to model a hierarchical relationship between two sets of records by connecting one record (the parent) to one or more related records (the children). This structure enables logical data grouping and is used to represent a master record along with its associated details. For example, there could be a list of customers (parent records), each with several orders (child records).

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FjLqXS6Kcgps4OM6Q3Yhk%2Fimage.png?alt=media&amp;token=d318ad78-f8f5-4452-9c0b-36b8ee2addf1" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

### **Note**

A single record in the master table can be linked to multiple records in the detail table, whereas each record in the detail table can only link to one record in the master table.
{% endhint %}

### **Benefits of adding a relation column**

Adding a relation column provides the following benefits:

* **Organized data structure:** Group related records to make complex datasets easier to navigate and understand.
* **Data integrity:** Maintain relationships between parent and child records to prevent incomplete or inconsistent data, such as an order item without an associated customer.
* **Streamlined data entry and updates:** Reduce data duplication by storing common information in parent records and allowing child records to inherit those values.
* **Simplified reporting and filtering:** Filter, summarize, and drill down into data by using parent-child relationships.
* **Improved user experience:** View and manage related parent and child records from a single interface.
* **Scaling and maintenance:** Scale your databases while maintaining data accuracy and integrity.

### Key components

A relation column uses the following components to establish a relationship between two tables:

* **Master table:** Contains the primary records. Each record represents a unique entity, such as a customer, project, or product.
* **Detail table:** Contains records that are related to a record in the master table. Multiple detail records can be associated with a single master record.
* **Foreign key column:** Stores the reference to the primary key in the master table, establishing the relationship between the two tables. PowerTable uses this column to link each detail record to its corresponding master record.

### Add a relation column

This section explains the steps to add a relation column and create master-detail linked tables using an example.

#### Prerequisite

If two or more tables in a dataset share a foreign key column, a master-detail relationship can be established between them.

#### Steps to add a relation column

In this example, you create a master-detail relationship between the **Product Subcategories** and **Products** tables. Both tables share the **ProductSubcategoryKey** column, which acts as a foreign key.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F1vENQHvnjzKEYSi2gsLV%2Fimage.png?alt=media&amp;token=11899df1-ad01-4e85-813b-97fead56d8f0" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FDPZAHq9vIYxqDntQiu5I%2Fimage.png?alt=media&amp;token=917a35c1-0fa6-4da3-800c-d879cda5fb13" alt=""><figcaption></figcaption></figure>

Optionally, configure the foreign key column as a [lookup column](/powertable-sheets/how-tos/configure-column-properties/lookup-and-relation.md) in the **Products** table to display the corresponding subcategory name from the **ProductSubcategories** table.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvPABXFyGwXKw95e1l8pg%2Fimage.png?alt=media&amp;token=bcb2719c-5364-45f9-a534-4925f36513b5" alt=""><figcaption></figcaption></figure>

To create the relationship, add a **relation column** to the master (subcategories) table.

1. Go to **Insert Column** > **Visual** **Column** > **Add Relation Column**. A side panel opens.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FHcNncE4RRpYHgy7HLvVH%2Fimage.png?alt=media&amp;token=9f2c67b5-4657-41a9-96d0-9ba1d2b1fd24" alt=""><figcaption></figcaption></figure>

2. Configure the column properties:

* **Column Name**: Enter a name for the relation column.
* **Relation Table**: Select the child table to relate to, such as **Products**.
* **Column from Current Table**: Select the column in the current (master) table that establishes the relationship.
* **Column from Relation Table**: Select the matching foreign key column in the related (child) table. *ProductSubcategoryKey* is the matching foreign key column in this example.
* **Column To Display**: Select the column whose values are displayed as reference labels for related records when you expand a record. In this example, select **Product Subcategory Key**. The corresponding lookup labels are displayed as reference labels for related records in the details table.
* **Display name for Relation Table**: Enter the text to display in the relation column. Users select this text to expand a record and view its related records.

3. **If Condition**: Optionally, select **Add Filter** to add one or more filter conditions. Combine multiple conditions by using **AND** or **OR**. PowerTable displays only related records that meet the specified conditions. For example, you can display child records only when the **Product Price** is more than a specific value.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FEBpJnKDMLpRzEPD2KLST%2Fimage.png?alt=media&amp;token=9ad2cfb5-2c7e-4c35-8df9-2e58407196e3" alt=""><figcaption></figcaption></figure>

4. **Cascade delete to linked records**: Enable this option to delete related child records automatically when the parent record is deleted.
5. The display properties for the relation column can be configured in the panel's **Display** tab. To learn more, see [Display](/powertable-sheets/how-tos/configure-column-properties/display.md).
6. Select **Save**.

The relation column is added to the subcategories table. The number of related child records for each parent record is displayed in parentheses.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FKYrmWiWLTWuTEqOxzpNk%2Fimage.png?alt=media&amp;token=144066ef-0389-4d2f-b3be-3ebf836367d0" alt="" width="563"><figcaption></figcaption></figure>

Expand a parent record to view its related child records. The related records open in a new table, identified by the selected subcategory label.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FBy1ROpgo3o13oq73jB87%2Fimage.png?alt=media&amp;token=a3595ea8-0d3e-4c76-af52-1f01fe8d0178" alt=""><figcaption></figcaption></figure>

In the details table, you can:

* Select [**Insert Row**](/powertable-sheets/how-tos/insert-import-duplicate-and-delete-rows.md#insert-rows) to add a new child record.
* Select [**Filter**](/powertable-sheets/how-tos/explore-and-organize-data/filter-data.md) to filter the displayed records.
* Select [**Sort By**](/powertable-sheets/how-tos/explore-and-organize-data.md#sort-records) to sort records by a specific column.
* Use the [**Search**](/powertable-sheets/how-tos/explore-and-organize-data.md#search-records) box to find records by using keywords.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.fabricplan.com/powertable-sheets/how-tos/adding-columns-overview/add-visual-column/relation-column.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
