Error message - "we encountered an error trying to save your calculated field. please try creating it again"

Hi all,

Getting an unknown error for a calculated field -

avgOver(ifelse({date} >= addDateTime(-7,‘DD’, now()) AND {date}<= now(), {sales} ,null),[{Product_name}])

Trying to get the average sales for a product for the past one week.

If I try to save it, it says - “we encountered an error trying to save your calculated field. please try creating it again”

I tried creating a new field and typed the formula again but the error isn’t resolved.
Is there anything wrong in the calculated field? or it’s some other issue?

Hi @phalguni24
can you try

avgOver(sum(ifelse({date} >= addDateTime(-7,‘DD’, now()) AND {date}<= now(), {sales} ,null)),[{Product_name}])

BR

1 Like

Hi @ErikG ,

Realized avgOver() wasnt needed, so this worked -
avg(ifelse({date} >= addDateTime(-7,‘DD’, now()) AND {date}<= now(), {sales} ,null))

One more doubt :

If i want to give max_date in my data instead of “now()”, then how would that work?

For example, If i try to do this,

avg(ifelse({date} >= addDateTime(-7,‘DD’, max(date) AND {date}<= max(date), {sales} ,null))

getting this error - Nesting of aggregate functions like {{aggregateFunction1}} and {{aggregateFunction2}} is not allowed.

Alright, found the issue,
had to create a calculated field with maxOver and pass it in place of “now()” :
maxOver({date}, [ ], PRE_AGG)

Working fine, thanks for the help Erik!