# CSV import: calculate average value

Our flow is configured to trigger as soon as the flow is started, imports a CSV file that we uploaded via the file upload interface of the CSV.ImportCSV utility, gets all the rows, calculate an average age of the persons in the CSV and sends the result via email. Our flow looks like this:<br>

<figure><img src="/files/K2JbjRBwMSkefD6Ahpq3" alt=""><figcaption><p>CSV import flow</p></figcaption></figure>

The **ImportCSV** utility from the CSV module is simply configured to read a file that we selected from our file system by clicking on the "*Select file*" input field:

<figure><img src="/files/jNUdNQNgQnseY9fmsMeF" alt=""><figcaption></figcaption></figure>

The content of our CSV sample file looks like this:

```
name,age
John,35
Jane,27
Peter,54
```

The configuration for the **GetRows** component uses the `fileId` variable from the **ImportCSV** component for the "*File ID*" input field. We also disabled the "*Filter rows*" parameter since we're interested in getting all the rows from the CSV file, not just an extracted subset. Also note that the "*Row format*" is set to "*Object*" so that the component gives us a formatted JSON list of all the rows in the form `[{col1: val1, col2: val2}, ...]`.

<figure><img src="/files/Qq4vAJIgIr9YhuzF6Cqr" alt=""><figcaption></figcaption></figure>

Next, we configure the final **SendEmail** component to send an email with the average age. The trick here is to calculate the average age by modifying the `rows` variable returned from **GetRows** component.

<figure><img src="/files/KzElJ8tMb4Xscf5YOOqv" alt=""><figcaption></figcaption></figure>

By clicking on the `rows` variable, we can configure our modifiers (data transformation functions) that calculate the average by first calculating the sum of all ages and dividing it by the number of items in the `rows` list:

<figure><img src="/files/mcp4ssntoGOQGhqlkseB" alt=""><figcaption></figcaption></figure>

Note that the modifiers can be stacked to produce more complex expressions. In the example above, we first "*Pick*" the `age` column only, apply "*Sum*" to the values and "*Div*" by the length of the `rows` list. Note that the length of the `rows` is defined by applying the nested "*Length*" modifier which we can do by clicking on the `rows` variable in the "*Div*" input field:

<figure><img src="/files/XaR1Rr4Cp0PwrQsxxC8o" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
A good practice is to test your modifiers using the "Test" functionality of the Modifiers panel:

{% endhint %}

<figure><img src="/files/nvzdGjugvOetxKNu3rSZ" alt=""><figcaption></figcaption></figure>

This is it! Now when we actually run our flow, we'll see a new email in our inbox with the average age of all the persons in our CSV file:

<figure><img src="/files/f3T3ZHmsHVgHpEHHug5i" alt=""><figcaption></figcaption></figure>

As a bonus for advanced users, we can also use a "low-code" alternative to our modifiers above by defining a JavaScript function modifier that will give us an average of values in our `age` column:

<figure><img src="/files/Es6xafJKyVRQSqBNicLC" alt=""><figcaption></figcaption></figure>

As you can see, the "*JavaScript Function*" modifier takes an arbitrary JavaScript code in which you can refer to the original variable with the `$variable` placeholder.


---

# Agent Instructions: 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:

```
GET https://docs.appmixer.com/kb/appmixer-studio-features/flow-examples/csv-import-calculate-average-value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
