Period Over Period Functions with Date Controls

Hi Zenia and Roy - I think that post above will help if you are building a line chart or bar chart where you want to show YoY of many data points at the same time. If you just want a single KPI but allow the user to filter to different date ranges, I would suggest using Parameter controls rather than Filter controls and then building all the YoY logic into your calculated field. Imagine you have two parameter date controls - start and end. Then your calc would look like this:

ifelse({order date}>=${start} and {order date}<=${end}, sales, 0) - ifelse({order date}>=addDateTime(-1, 'YYYY',${start}) and {order date}<=addDateTime(-1, 'YYYY',${end}), sales, 0)

You could break it down into 3 calcs instead (which would allow you to use the Current Period and Same Period Last Year values by themselves if you wanted, and then your 3rd calc just does the arithmetic using those to do either YoY or YoY %.

Current Period: ifelse({order date}>=${start} and {order date}<=${end}, sales, 0)

Same Period Last Year: ifelse({order date}>=addDateTime(-1, 'YYYY',${start}) and {order date}<=addDateTime(-1, 'YYYY',${end}), sales, 0)

YoY: sum({Current Period}) - sum(Same Period Last Year})

YoY %: sum({Current Period}) / sum(Same Period Last Year}) -1

Check out this working example: https://democentral.learnquicksight.online/#Dashboard-TipsAndTricks-Calculation-YoY-using-parameters