# Apply transform conditioning on laged values

**URL:** <https://discourse.julialang.org/t/apply-transform-conditioning-on-laged-values/109777>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [February 6, 2024, 4:51am UTC](https://discourse.julialang.org/t/apply-transform-conditioning-on-laged-values/109777 "2024-02-06T04:51:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelborrero](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Post date:** [February 6, 2024, 4:51am UTC](https://discourse.julialang.org/t/apply-transform-conditioning-on-laged-values/109777/1 "2024-02-06T04:51:32Z")

</div>

Hi there,

I am trying to add a column in my DataFrame by using the function transform. I need to groupby a couple of categories and then calculate add a new column based on the lagged values of each row. The reason why I need to groupby is that I do not want to take as lagged values observations from other groups and therefore I need the transformation to be within groups.

However, I do not seem to find how transform allows for this.

Thanks a lot,  
Miguel.

---

<div class="post-metadata">

**Author:** ![klwlevy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klwlevy/32/25272_2.png) [@klwlevy](https://discourse.julialang.org/u/klwlevy)\
**Post date:** [February 6, 2024, 6:12am UTC](https://discourse.julialang.org/t/apply-transform-conditioning-on-laged-values/109777/2 "2024-02-06T06:12:26Z")

</div>

> **[Back to the basics: don’t lag behind with your DataFrames.jl skills](https://bkamins.github.io/julialang/2022/09/23/lagging.html)**
>
> Introduction
