# WindowAVG with negative parameter

**URL:** <https://community.amazonquick.com/t/windowavg-with-negative-parameter/45062>\
**Category:** Q&A\
**Tags:** error, developer, quick-sight\
**Created:** [April 16, 2025, 1:26pm UTC](https://community.amazonquick.com/t/windowavg-with-negative-parameter/45062 "2025-04-16T13:26:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![COSTA](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@COSTA](https://community.amazonquick.com/u/COSTA)\
**Post date:** [April 16, 2025, 1:26pm UTC](https://community.amazonquick.com/t/windowavg-with-negative-parameter/45062/1 "2025-04-16T13:26:22Z")

</div>

Hello,  
I need to create a calculated field with the following structure. I need to calculate the average of a field that starts 3 lines before the current line and ends one line before the current line.

However, Quicksight has a limitation: it does not allow us to pass a negative number as the end. In the end parameter, Quick Sight only allows positive numbers below the current line. I need to start from the previous line.

How can I get around this limitation?

This is an example of what I need:

windowAvg(sum({Camop1}),[date],3,-1)

---

<div class="post-metadata">

**Author:** ![Xclipse](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/xclipse/32/20455_2.png) [@Xclipse](https://community.amazonquick.com/u/Xclipse)\
**Post date:** [April 18, 2025, 5:08am UTC](https://community.amazonquick.com/t/windowavg-with-negative-parameter/45062/2 "2025-04-18T05:08:01Z")

</div>

Hi @COSTA

Unfortunately, [windowAvg](https://docs.aws.amazon.com/quicksight/latest/user/windowAvg-function.html) function does not support negative offsets, so it’s not possible to directly define a window that ends before the current row (e.g., start=3, end=-1).

To work around this, I’ve recreated the logic using [lag](https://docs.aws.amazon.com/quicksight/latest/user/lag-function.html) functions to calculate the average of the previous 3 rows. Here’s how it works

**Example:**

```auto
Lag1 = lag(sum(Sales), [OrderDate ASC], 1)
Lag2 = lag(sum(Sales), [OrderDate ASC], 2)
Lag3 = lag(sum(Sales), [OrderDate ASC], 3)

Compute the average:

AVGLAG = (Lag1 + Lag2 + Lag3) / 3

```

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/b/8/b872da4994122cd362f0150147ccb32d6a4f60cd.png)

---

<div class="post-metadata">

**Author:** ![Brett](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/brett/32/36494_2.png) [@Brett](https://community.amazonquick.com/u/Brett)\
**Post date:** [April 29, 2025, 9:16pm UTC](https://community.amazonquick.com/t/windowavg-with-negative-parameter/45062/3 "2025-04-29T21:16:19Z")

</div>

Hi @COSTA,  
It’s been awhile since we last heard from you, did you have any additional questions regarding your initial post?

If we do not hear back within the next 3 business days, I’ll close out this topic.

Thank you!

---

<div class="post-metadata">

**Author:** ![Brett](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/brett/32/36494_2.png) [@Brett](https://community.amazonquick.com/u/Brett)\
**Post date:** [May 2, 2025, 2:54pm UTC](https://community.amazonquick.com/t/windowavg-with-negative-parameter/45062/4 "2025-05-02T14:54:42Z")

</div>

Hi @COSTA,  
Since we have not heard back, I’ll go ahead and close out this topic. However, if you have any additional questions, feel free to create a new post in the community.
