Skip to main content

Recursion Agent

The Recursion agent recursively calculates data across levels in a parent-child tree.

Updated today

Overview

The Recursion agent allows you to perform calculations row by row across all levels in a parent-child relationship tree within your dataset. This agent is designed to help you gain deeper insights and perform complex calculations within hierarchical data structures.

Use Cases

  • Recursively Calculate Data: The Recursion agent calculates data row by row across all levels in a parent-child tree, making it possible to analyze and manipulate hierarchical data effortlessly.

  • Trace Parent-Child Relationships: By specifying the unique IDs (ID and Parent ID), the Recursion agent recursively traces the relationship between parent and child rows, providing valuable insights into the structure of your data.

  • This agent ool outputs the depth and path for each row. The top-level parent in each family of rows has a depth of 1. The child of that row has depth 2, and so on. The path field gives the list of IDs from the top-level parent to the current row.

Example

Input

ID

Manager ID

Name

1

Jane

2

1

Pat

3

2

Alex

Output

ID

Manager ID

Name

Depth

Path

1

Jane

1

1

2

1

Pat

2

1 > 2

3

2

Alex

3

1 > 2 > 3

Configuration

โš ๏ธ Top-level ID: Make sure that the top level of your hierarchy always has a value in the ID field. Without this value, the agent won't be able to establish the hierarchy correctly.

  1. Select ID Field: Choose the field in your dataset that represents the unique ID for each individual row. For example, you might select "Employee ID."

  2. Select Parent ID Field: Specify the field that contains the ID of the specific row's parent. This establishes the parent-child relationship within your data.

  3. Aggregation (Optional): You can add aggregation to your hierarchy calculations to perform specific calculations on the data. To do this:

    a. Click the plus sign (+) to add an aggregation.

    b. Select an argument for your aggregation.

    c. Define your calculation, new field name, and select a delimiter if needed.

  4. Click "Apply" to save your settings.


Output Fields

The Recursion agent generates specific output fields that you can use in your analysis. Here are the key output fields:

  1. Depth: This field represents the depth or path from the top of the hierarchy to the current row, including the current row.

  2. Path: Path is a concatenation of the hierarchy of the impacted employee IDs that Savant recursively traces from parent to the current row.


Troubleshooting

Try to avoid loops in your data, where nodes reference a descendent as a parent. Here is an example:

As you see, node 5 references it's great-grand-child as it's parent. In this case, the Recursion agent will stop tracing after node 5 connects to node 2. The final path would show: 1 > 2 > 3 > 4 > 5 > 2

We also recommend avoiding duplicate parent-child relationships in your data. Savant will ignore them, removing the duplicate relationships, and continue to trace your hierarchy.

Did this answer your question?