> ## Documentation Index
> Fetch the complete documentation index at: https://gql.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# COLLECT_LIST

> COLLECT_LIST function collects values into a list

Collects values into a list

### Calculating Geometric Mean using COLLECT\_LIST and REDUCE

Geometric Mean is a measure of central tendency that calculates an average of the data using multiplication instead of addition. For a set of n numbers, the geometric mean is the nth root of the product of those numbers. For example, the geometric mean of the numbers 2, 3, and 14 equals (2 \* 3 \* 14)1/3 = (84)1/3 = 4.37952. Geometric Mean is particularly useful when the data is skewed and a simple average does not work.

Suppose we are interested in the Geometric Mean Income of all the people who live in the same city as Fatima:

```mermaid theme={null}

%%{init: {'theme':'base', 'themeVariables': {'lineColor':'#F1FA8C','secondaryColor':'#F1FA8C','background':'#282A36'}}}%%
graph LR

    subgraph row1[" "]

    saqib[<b>:person</b><br/>name: Saqib👨<br/>income: 375000]
    scott[<b>:person</b><br/>name: Scott 👨<br/>income: 205000]
    fatima[<b>:person</b><br/>name: Fatima 👩<br/>income: 195000]
    hannah[<b>:person</b><br/>name: Hannah 👩<br/>income: 185000]
    zainab[<b>:person</b><br/>name: Zainab 👩<br/>income: 190000]
    capitola[<b>:city</b><br/>name:Capitola]

    end

    subgraph row2[" "]
    eleni[<b>:person</b><br/>name: Eleni 👩<br/>income: 185000]
    uroosa[<b>:person</b><br/>name: Uroosa 👩<br/>income: 175000]
    angela[<b>:person</b><br/>name: Angela 👩<br/>income: 195000]
    maryam[<b>:person</b><br/>name: Maryam 👩<br/>income: 155000]
    santacruz[<b>:city</b><br/>name:Santa Cruz]
    end

    subgraph row3[" "]
    laila[<b>:person</b><br/>name: Laila 👩<br/>income: 180000]
    huda[<b>:person</b><br/>name: Huda 👩<br/>income: 172000]
    end

    %% saqib -->|:relationship<br/>type: co-worker| fatima
    %% fatima -->|:relationship<br/>type: friend| eleni
    %% eleni -->|:relationship<br/>type: friend| uroosa
    %% saqib -->|:relationship<br/>type: friend| angela
    %% angela -->|:relationship<br/>type: co-worker| scott
    %% scott -->|:relationship<br/>type: friend| uroosa


    saqib -->|<b>:lives_in</b>| capitola
    scott -->|<b>:lives_in</b>| capitola
    fatima -->|<b>:lives_in</b>| capitola
    hannah -->|<b>:lives_in</b>| capitola
    zainab -->|<b>:lives_in</b>| capitola



    angela -->|<b>:lives_in</b>| santacruz
    uroosa -->|<b>:lives_in</b>| santacruz
    eleni -->|<b>:lives_in</b>| santacruz
    maryam -->|<b>:lives_in</b>| santacruz


    classDef nodes fill:#BD93F9,stroke-width:0px
    class saqib,fatima,angela,uroosa,eleni,scott,maryam,zainab,hannah,huda,laila nodes

    classDef subgraphStyle fill:#282A36, stroke-width:0px
    class row1,row2,row3 subgraphStyle
```

```gql theme={null}
match path = ALL  (a {_id:'fatima'})-[:lives_in]->(b)<-[:lives_in]-(c)
return COLLECT_LIST(c) as residents
next
return reduce (geo_mean_product = 1, resident in residents | resident.income * geo_mean_product)  ^ (1.0 / LENGTH(residents)) as income_geometric_mean;
```

Note that we first use the [COLLECT\_LIST](/docs/functions/collect-list) to get all the people who live in the same city as Fatima in a LIST. Next we use the [REDUCE](/docs/functions/reduce) to calculate the Geometric Mean.

An alternate way to calculate Geometric Mean would be:

```gql theme={null}
match path = ALL  (a {_id:'fatima'})-[:lives_in]->(b)<-[:lives_in]-(c)
return exp(AVG(ln(c.income))) as income_geometric_mean;
```
