# Sorting loop elements

Use a SimpleLoop function with an AscendingSort function to sort elements in a loop based on their value.

## Before you begin

You have created a map with an input and output structure. You can use the sample provided below.

## About this task

In this example, you have a CSV file containing employee information. You want to sort the list of employees alphabetically by their last names. You can use the following CSV sample to create a structure and use it as both input and output in your map:

```
firstName,lastName,salary
Steve,Rogers,185
Tony,Stark,200
Natasha,Romanoff,175
Bruce,Banner,150
Clint,Barton,135
```

## Procedure

1. Drag and drop the input row element on the corresponding output to map all child elements.

   A SimpleLoop function is automatically added to the output row loop. ![](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/Resources/images/sort_by_value_01_simpleloop.png)
2. Drag and drop a AscendingSort function on the Sort Keys argument.
3. Drag and drop the input lastName element on the AscendingSort function.

## Results

Your map is configured and should look like this: ![](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/Resources/images/sort_by_value_02_ascendingsort.png)

You can use the Test Run feature to see the result. In this example, the following output is returned:

```
firstName,lastName,salary
Bruce,Banner,150
Clint,Barton,135
Steve,Rogers,185
Natasha,Romanoff,175
Tony,Stark,200
```