# Using lag with sumover

**URL:** <https://community.amazonquick.com/t/using-lag-with-sumover/5436>\
**Category:** Q&A\
**Tags:** filters, error, calculations, quick-sight\
**Created:** [August 16, 2022, 1:57pm UTC](https://community.amazonquick.com/t/using-lag-with-sumover/5436 "2022-08-16T13:57:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [August 18, 2022, 2:07am UTC](https://community.amazonquick.com/t/using-lag-with-sumover/5436/3 "2022-08-18T02:07:08Z")

</div>

Hi @sherif.elshaer -

I’ve confirmed the `lag` function will allow you to nest `sumOver` within it without applying aggregation . Thank you for raising this concern here. I’ve reproduced the error and will be investigating.

To use a LAC-W within a table calculation you can use

```auto
lag(max(sumover({sales},[],PRE_FILTER)),[financialyear ASC],1,[{Level 2},{Level 3},{Level 4},{Level 5}])

```

For your use case, the `lag` function won’t help here since it’s a [table calculation](https://docs.aws.amazon.com/quicksight/latest/user/table-calculation-functions.html). What this means is that the data must be in your visual dataset, or to use an analogy the `lag` function can only access what’s “on the table”. Once you filter your visual to a specific year like 2016 then `lag` can’t access the 2015 rows. [Check out this order of evaluation doc for more detail.](https://docs.aws.amazon.com/quicksight/latest/user/order-of-evaluation-quicksight.html)

To accomplish what you want you’ll need to use parameters. Check out this awesome guide for some approaches [Period Over Period and Other Date Comparison Calculations (YoY, MoM, YTD, Rolling 90 days, etc)](https://community.amazonquick.com/t/period-over-period-and-other-date-comparison-calculations-yoy-mom-ytd-rolling-90-days-etc/564)

Example:

Step 1 - Create a Year Parameter and add a control for it.

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/8/8a748238a391cc3bd3d17a46e40a0f39339d0bba.png)

Step 2 - Create a current year sales calculated field  
c\_sales\_current\_year  
`sumif(Sales,{c_extract_year}=${pYear})`

Step 3 - Create a previous year sales calculated field  
c\_sales\_previous\_year  
`sumif(Sales,{c_extract_year}=${pYear}-1)`

Result:

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/3/3c34f41a31afd0fac3f32747accbbfdea0312779.png)

---

_[View the full topic](https://community.amazonquick.com/t/using-lag-with-sumover/5436)._
