DATETIME_ADD with parameter yields error

I am trying to pass in an integer parameter value to the DATETIME_ADD() function but it just yields an "Invalid formula" error:

 

DATETIME_ADD(TODAY(), INTERVAL my_parameter WEEK)

 

If I multiply or add another integer value on the parameter inside the function, I get an OK checkmark for the formula and it calculates correctly:

 

DATETIME_ADD(TODAY(), INTERVAL my_parameter * 2 WEEK)

 

If I do a calculation with non-integers and try to get the integer value of that calculation inside the function, I get the OK checkmark but the output fails with an error "Data Set Configuration Error":

 

DATETIME_ADD(TODAY(), INTERVAL FLOOR(my_parameter / 2) WEEK)

 

What on Earth's is happening and why can't all calculations be done on the parameter inside this function?

EDIT: Corrected WEEKS to WEEK in the formulas 🤦

0 2 317
2 REPLIES 2

Hate to be that unhelpful guy, but it works for me. Only thing I changed is to say WEEK rather than WEEKS, although I'm guessing you already did that as otherwise your second example shouldn't work.

Spreadsheep_0-1723241311457.png

 

Dear @Spreadsheep. Good catch and unfortunately that was not the culprit. It's down to I can't get rid of float values in the formula it seems. the multiply by integer does not convert a number to float while a division always does. Dunno why the FLOOR() won't convert back to integer again, though.