# Sort by Formula Generator

The Sort by Formula generator allows you to order your structure based on the results of a formula.

The structure above sorts issues by the number of days until they are due, using the simple formula: `DAYS_BETWEEN(NOW(), dueDate)`

## Sorting a Structure

To add a Sort by Formula generator, open the **Add **menu and select **Sort**.

This will display the Sort generator options. Select **Formula**.

## Configuring the Generator

Next, you'll configure the Sort generator.

**Formula**

Enter the formula you want to use to sort the structure. The formula results will be calculated for each row of the structure, based on the variable values for that row.

To learn more about working with formulas, see Formula Basics and Formula Reference Documentation.

**Sort Direction**

Select whether issues should be sorted in ascending or descending order.

**Sort Levels**

Allows you to specify which levels in the hierarchy will be sorted:

- Levels are based on the placement of the generator, where "Level 1" is the level the generator is located on, "Level 2" is the level beneath that, and so on.
- To apply the sort to every level on or below the generator's level, select
**All levels**.*Note: items above the Sorter will not be sorted.* *See Level-based Sorting to learn more about customizing levels.*