# Get value of column corresponding to condition being met for another column in a Grouped DataFrame

**URL:** <https://discourse.julialang.org/t/get-value-of-column-corresponding-to-condition-being-met-for-another-column-in-a-grouped-dataframe/69586>\
**Category:** New to Julia\
**Tags:** data, dataframes\
**Created:** [October 11, 2021, 8:28pm UTC](https://discourse.julialang.org/t/get-value-of-column-corresponding-to-condition-being-met-for-another-column-in-a-grouped-dataframe/69586 "2021-10-11T20:28:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtomar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vtomar/32/18304_2.png) [@vtomar](https://discourse.julialang.org/u/vtomar)\
**Post date:** [October 11, 2021, 8:28pm UTC](https://discourse.julialang.org/t/get-value-of-column-corresponding-to-condition-being-met-for-another-column-in-a-grouped-dataframe/69586/1 "2021-10-11T20:28:52Z")

</div>

```julia
using DataFrames, DataFramesMeta
df = DataFrame(x = [1,1,1,2,2,2], y = [1,2,3,101,102,103], z = [5, 6, 7, 505, 506, 507])
gdf = groupby(df, :x)
@combine(gdf, :MaxY = maximum(:y))

```

Above is MWE. I group by x column and find the max of y column and need the corresponding value of z being returned for each group’s max y value.

I am not sure how to get the corresponding z value? Help appreciated

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [October 11, 2021, 8:37pm UTC](https://discourse.julialang.org/t/get-value-of-column-corresponding-to-condition-being-met-for-another-column-in-a-grouped-dataframe/69586/2 "2021-10-11T20:37:09Z")

</div>

```julia
julia> @combine(gdf, :Maxz = :z[argmax(:y)])
2×2 DataFrame
 Row │ x Maxz
     │ Int64 Int64
─────┼──────────────
   1 │ 1 7
   2 │ 2 507

```

(assuming that you have a unique maximum value)
