# Find max value without grouping

**URL:** <https://community.riskscape.org.nz/t/find-max-value-without-grouping/187>\
**Category:** Community\
**Created:** [12 September 2024 02:42 UTC](https://community.riskscape.org.nz/t/find-max-value-without-grouping/187 "2024-09-12T02:42:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPowell](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@JPowell](https://community.riskscape.org.nz/u/JPowell)\
**Post date:** [12 September 2024 02:42 UTC](https://community.riskscape.org.nz/t/find-max-value-without-grouping/187/1 "2024-09-12T02:42:55Z")

</div>

This pipeline will return the maximum value for each unique group in column ‘A’

```auto
-> group(
by: A,
select: {max: {A, max(B)}}
)
-> save(name: 'output')

```

so

```auto
A,B
a,1
a,4
g,3
g,2

```

will return

```auto
max.A,max.max_B
a,4
g,3

```

I would like to get the maximum value in column ‘B’ but removing the group function

```auto
input(relation: 'test.csv')
-> select({max(B)})
-> save(name: 'output')

```

gives the error

```auto
Failed to validate model for execution
  - Failed to validate 'select({max(B)})' step for execution
    - Failed to validate expression '{max(B)}' against input type {A=>Text, B=>Text}
      - Problems found with 'max' riskscape function
        - Wrong number of arguments provided. Expected 2, but got 1

```

How can I use max with a column of data outside of a group function?

---

<div class="post-metadata">

**Author:** ![timbeale](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@timbeale](https://community.riskscape.org.nz/u/timbeale)\
**Post date:** [12 September 2024 03:15 UTC](https://community.riskscape.org.nz/t/find-max-value-without-grouping/187/2 "2024-09-12T03:15:01Z")

</div>

Hi John,

Why do you want to get rid of the `group` step?

Basically the `group` step aggregates across several rows of data, whereas the `select` step processes each row of data separately (i.e. it operates on a scalar value). So the `select` step only ever sees _one_ value for column B at a time.

The slightly confusing thing here is that the `max()` function can be used both in scalar-mode (i.e. `select` step) and aggregate-mode (i.e. `group` step). In the scalar version it expects to compare _two_ numbers and return the higher number, e.g. `max(B, C)`. This is why it’s giving you this error.

If all you want to do here is get the max across _all_ the rows of data, then you could just remove the `by` clause from the `group` step, i.e.

```auto
input(relation: 'test.csv')
-> group({max(B)})
-> save(name: 'output')

```

Cheers,  
Tim
