# Dynamically changing Period over Period calculation

**URL:** <https://community.amazonquick.com/t/dynamically-changing-period-over-period-calculation/30195>\
**Category:** Q&A\
**Tags:** analysis, calculated-field, error, Business-Intelligence-Engineer, quick-sight\
**Created:** [May 17, 2024, 1:39pm UTC](https://community.amazonquick.com/t/dynamically-changing-period-over-period-calculation/30195 "2024-05-17T13:39:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![resjames](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@resjames](https://community.amazonquick.com/u/resjames)\
**Post date:** [May 17, 2024, 1:39pm UTC](https://community.amazonquick.com/t/dynamically-changing-period-over-period-calculation/30195/1 "2024-05-17T13:39:59Z")

</div>

I have calculated field to calculate the WoW difference. My Dashboard has a control to change the aggregation from Daily/Weekly/Monthly. However, the WoW doesn’t change to DoD or MoM  
`periodOverPeriodDifference({Metric value}`  
` ,{time frame group(date)}`  
` ,'WEEK'`  
` ,1)`

I tried the below but threw an error saying expected is a period  
`periodOverPeriodDifference({Metric value}`  
` ,{time frame group(date)}`  
`ifelse(`  
` ${TimeFrame} = 'Monthly' , MONTH,`  
` ${TimeFrame} = 'Weekly' , WEEK,`  
` ${TimeFrame} = 'Daily',DAY,`  
` WEEK`  
` )`  
`,`  
`)`  
Is there a way to pass period from string

---

<div class="post-metadata">

**Author:** ![WLS-DM](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/wls-dm/32/36109_2.png) [@WLS-DM](https://community.amazonquick.com/u/WLS-DM)\
**Post date:** [May 18, 2024, 10:41pm UTC](https://community.amazonquick.com/t/dynamically-changing-period-over-period-calculation/30195/2 "2024-05-18T22:41:51Z")

</div>

Hello @resjames, welcome to the Quick Sight community!

I think if you changed the logic to have the periodOverPeriod functions returned as the result of the ifelse statement rather than trying to change the period value in the calculation, you may have more success. I’ll put an example below:

```auto
ifelse(
${TimeFrame} = 'Weekly',
periodOverPeriodDifference(sum({Metric value}), {time frame group(date)}, WEEK, 1),
${TimeFrame} = 'Daily',
periodOverPeriodDifference(sum({Metric value}), {time frame group(date)}, DAY, 1),
periodOverPeriodDifference(sum({Metric value}), {time frame group(date)}, MONTH, 1)
)

```

This would check for the period selected by the user and return the calculated field with the proper aggregation. I’ll mark this as the solution, but let me know if you have any remaining questions. Thank you!
