How to create a calculated field YoY with multiple controls parameters?

hello!
I’m trying to calculate the difference from one year to another in year -1 of a field filtered on date parameters: “startDate” & “EndDate” .
I tried this:
ifelse(dateDiff(timestamp_extracted, ${startDate} AND ${endDate},“MM”)=12 AND
timestamp_extracted<=addDateTime(-1,“YYYY”,${startDate} AND ${endDate}),sales,0)
but I have some syntax errors or more!

Have you tried using periodoverperiodtimedifference instead?

It will take into account the filters of your visual.

Hello Max, thank you for your answer.
I tried this solution:

periodOverPeriodDifference(countIf(sessionuuid, {timestamp_extracted}>=${startDate} AND {timestamp_extracted}<=${endDate} AND in(event, [“init”])), {timestamp_extracted}, YEAR, 1)

But when I enter this calculated field in the parameters the result obtained is data = 0
In fact I would like to have a comparaison between the period requested thougth the controls parameters and the same period one year before.
For example we could have: from 1/01/2023 to 01/04/2023 i want to show the difference with the same date one year before.
Date parameters are modifiable, my calculated field must synchronize with that.

Can you try this

periodOverPeriodDifference(countOver(ifelse( {timestamp_extracted}>=${startDate} AND {timestamp_extracted}<=${endDate} AND {event}='init', {sessionuuid},NULL),[],PRE_AGG), {timestamp_extracted}, YEAR, 1)

I tried your solution, but it doesn’t work. The function expression contains an unsupported date. I tried to add “addDateTime” but i don’t can implement this correctly an i wonder if it is possible or if it is not necessary to rethink completely the calculation?

Are you sure your date field is a date and your parameters are dates?