# Previous Year Total values (at Quarterly Level) in Quicksight

**URL:** <https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689>\
**Category:** Q&A\
**Tags:** error, calculations, quick-sight\
**Created:** [March 30, 2023, 5:41pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689 "2023-03-30T17:41:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chabbils](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/chabbils/32/7707_2.png) [@chabbils](https://community.amazonquick.com/u/chabbils)\
**Post date:** [March 30, 2023, 5:41pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/1 "2023-03-30T17:41:13Z")

</div>

Hi Team, in the attached screenshot, I’ve Units (CY), Total Units (CY) and Units (PY). I want to create a calculated field for **Total Units (PY)** (having a value of 334.1M against each record as per attached screenshot). I tried creating the same but not getting the right values. Can you please help me with this? Below is how my calculated fields look like:

- Total Units (CY) : sum(Units,[{Reporting Date},{Reporting Grain},Marketplace])
- Units (PY) : periodOverPeriodLastValue(sum(Units), {Reporting Date}, YEAR, 1)

 ![Screenshot 2023-03-03 at 18.03.35](https://d1wl4jav5dp96l.cloudfront.net/original/2X/3/38d265648ae77536abb09f0141097a7a9bc33f45.png)

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [March 30, 2023, 10:07pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/2 "2023-03-30T22:07:11Z")

</div>

> [@chabbils](#):
>
> sum(Units,[{Reporting Date},{Reporting Grain},Marketplace])

Do you need to do this to your py as well?

---

<div class="post-metadata">

**Author:** ![chabbils](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/chabbils/32/7707_2.png) [@chabbils](https://community.amazonquick.com/u/chabbils)\
**Post date:** [March 31, 2023, 7:11pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/3 "2023-03-31T19:11:53Z")

</div>

> [@Max](#):
>
> sum(Units,[{Reporting Date},{Reporting Grain},Marketplace])

@Max I already tried it. It shows attached error.

 ![Screenshot 2023-03-31 at 21.11.21](https://d1wl4jav5dp96l.cloudfront.net/original/2X/1/135d79e4c661a55c41acbf1addf5fa40a9c8941f.png)

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [April 3, 2023, 5:32pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/4 "2023-04-03T17:32:37Z")

</div>

can you try using a sumOver with a pre\_agg?

sumOver(Units,[{Reporting Date},{Reporting Grain},Marketplace],PRE\_AGG)

---

<div class="post-metadata">

**Author:** ![chabbils](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/chabbils/32/7707_2.png) [@chabbils](https://community.amazonquick.com/u/chabbils)\
**Post date:** [April 4, 2023, 12:38pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/5 "2023-04-04T12:38:47Z")

</div>

@Max I tried but not getting the required result/value. It’s giving me Negative values. Screenshot attached. Please help.

 ![Screenshot 2023-04-04 at 14.37.35](https://d1wl4jav5dp96l.cloudfront.net/original/2X/e/ee83fcc70155a6d2f3729dba90b70ba9ca808761.png)

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [April 4, 2023, 2:32pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/6 "2023-04-04T14:32:49Z")

</div>

What is your exact calculation now?

---

<div class="post-metadata">

**Author:** ![chabbils](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/chabbils/32/7707_2.png) [@chabbils](https://community.amazonquick.com/u/chabbils)\
**Post date:** [April 4, 2023, 3:15pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/7 "2023-04-04T15:15:49Z")

</div>

@Max see attached screenshot.

 ![Screenshot 2023-04-04 at 17.15.04](https://d1wl4jav5dp96l.cloudfront.net/original/2X/9/957345b2c6b8ceba5e2929383608d08bb8b9fb05.png)

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [April 5, 2023, 6:00pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/8 "2023-04-05T18:00:02Z")

</div>

That’s your calculation for Total Units (Previous Year)? You must have negative units.

---

<div class="post-metadata">

**Author:** ![chabbils](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/chabbils/32/7707_2.png) [@chabbils](https://community.amazonquick.com/u/chabbils)\
**Post date:** [April 6, 2023, 9:27am UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/9 "2023-04-06T09:27:54Z")

</div>

@Max Yes, I created this calculation based on the formula you mentioned above but my ask is different. I want to create a calculated field under **Total Units (PY)** having a value of 334.1M against each record as per attached screenshot, the way I’ve 471.9M under **Total Units (CY)** against each record.

---

<div class="post-metadata">

**Author:** ![apjvinod](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@apjvinod](https://community.amazonquick.com/u/apjvinod)\
**Post date:** [April 10, 2023, 3:34am UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/10 "2023-04-10T03:34:06Z")

</div>

@chabbils I assume you want to calculate total units for the same quarter last year in the pivot table .

Please use the below expression to calculate it , ensure to keep the same level for the current year & previous year measure .

periodOverPeriodLastValue(sumover(sum({Units}),[{Reporting Date}]),{Reporting Date},QUARTER,4)

I have tried in a sample dataset and it works . Please see screenshot

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/a/a2822b8463e625017cc1cff99b4b0043a7347f87.png)  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/7/7064a47708fad7efa513cbfa54d71a1faccd339a.png)

Did my suggestion help you in resolving your query? If yes, would request you to mark the post as “Solution”.  
This will help the community to find guidance and answers to similar question.

Thanks  
VInod

---

<div class="post-metadata">

**Author:** ![chabbils](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/chabbils/32/7707_2.png) [@chabbils](https://community.amazonquick.com/u/chabbils)\
**Post date:** [April 29, 2024, 3:37pm UTC](https://community.amazonquick.com/t/previous-year-total-values-at-quarterly-level-in-quicksight/11689/11 "2024-04-29T15:37:27Z")

</div>

> [@apjvinod](#):
>
> periodOverPeriodLastValue(sumover(sum({Units}),[{Reporting Date}]),{Reporting Date},QUARTER,4)

Thanks @apjvinod , i was able to implement it.
