Hi everyone, I’m currently trying to calculate a PY YTD and PY MTD metric for a sum of XEVs variable. I’ve tried many different ways, either by creating a field for PY date (vehicle_retail_date_py), either by calculating it by hand, and the closest I managed to achieve, is the following code, but I stand on a specific and rather strange error:
“Expression addDateTime(-1, ‘YEAR’, now()) for function addDateTime has incorrect argument type addDateTime(Number, String, Date). Function syntax expects Numeric, String, Date.”
Could you explain to me the difference between a “Number” and a “Numeric” in Quicksight data types?
How could I fix this code?
ifelse(
${Period} = "YTD",
sum(
ifelse(
vehicle_retail_date >= formatDate(
concat(
formatDate(
extract('YYYY', addDateTime(-1, 'YEAR', now())),
'0000'
),
'-',
formatDate(
extract('MM', addDateTime(-1, 'YEAR', now())),
'00'
),
'-01'
),
'yyyy-MM-dd'
)
AND vehicle_retail_date <= formatDate(now(), 'yyyy-MM-dd'),
XEVs,
NULL
)
) ,
${Period} = "MTD",
sum(
ifelse(
extract('DD', now()) - extract('DD', {vehicle_retail_date}) >= 0,
XEVs,
NULL
)
),
${Period} = "ACT",
sum(XEVs),
0
)