Concat with ifelse statement

Hi All,

Would request your help with the below calculated field.

I am trying to add a concat function, which basically reflects it as 1 year or 2 year if the datediff is greater than 1 year and if the datediff is less than 1 year then reflect it as a 1 month, 2 months.

The ${YEARPARAMETER} is a rolling date

I am not sure where should I include the concat function to get the desired result

toString(ifelse(dateDiff({Created Date}, ${YEARPARAMETER}, ‘YYYY’) >1, dateDiff({Created Date}, ${YEARPARAMETER}, ‘YYYY’), dateDiff({Created Date}, ${YEARPARAMETER}, ‘MM’)))

Thanks,
Akshay

Hi @akshaym
sorry but I don’t get it what you would like to contact.
But concat(string,string,string) is the syntax.

BR

Hi @ErikG,

Apologies if my question didn’t seem to be clear.

I will try to state my request clearly.

So, ${YEARPARAMETER} is a rolling date which always takes the previous day which in this case would be (1/7/2024).

My ifelse statement is basically trying to see if the (created date - rolling date ) looking for the year is greater than one then, I want to basically have the difference and add “years” using concat function. And if it is less than one year then the (created date - rolling date) looking for the month and add “month” using concat function.

image

Thanks,
Akshay

Ok, so something like:

concat(toString(“the difference as number”)," ",ifelse(diff>=1year,“year”,“month”))

@ErikG,

I think my ifelse statement logic is wrong. Because while it does return me the datediff in months if the year >= 1, but using your concat(toString(“the difference as number”)," ",ifelse(diff>=1year,“year”,“month”)) what happens is if the returned month is also greater than 1 it returns it as 2 years. So for example if my created date was 11/10/2023, it should have returned 2 months, but rather it returns it as 2 years. Could you help me fix the logic. So that in the same ifelse statement I can get the year and at the same time the month if the year is less than 1.

Thanks,
Akshay

Could you share your formula?

what about:
ifelse(dateDiff({Created Date}, ${YEARPARAMETER}, ‘YYYY’) >1,
concat(toString(dateDiff({Created Date}, ${YEARPARAMETER}, ‘YYYY’)," Year"), concat(toString(dateDiff({Created Date}, ${YEARPARAMETER}, ‘MM’)," Months")))

Hi @ErikG ,
Here is the formula I am using

ifelse(dateDiff({Created Date}, ${YEARPARAMETER}, ‘YYYY’) >1, dateDiff({Created Date}, ${YEARPARAMETER}, ‘YYYY’), dateDiff({Created Date}, ${YEARPARAMETER}, ‘MM’))

But the logic itself is wrong, because although the ifelse statement fetch’s the MM for me if the datediff is less than 1 year. However, if the month is even 1 month, 2 months, the concat(toString(“the difference as number”)," ",ifelse(diff>=1year,“year”,“month”))'

still returns it as year. How can I correct the logic itself to return year if greater than 1 and month/s if less than 1 year

Hi @akshaym
what if you do the datediff on month an if >12 its year. Seems like the smallest value on YYYY is always 1.
See also the samples

BR

Hi @ErikG ,

Thank you for your help.

The logic needed to be tweaked a bit, but without your help it won’t have been possible.

Here is the updated calculated field


ifelse(dateDiff({Created Date}, ${YEARPARAMETER}, 'MM') > 12, concat(toString(dateDiff({Created Date}, ${YEARPARAMETER}, 'YYYY')), ' Years'), concat(toString(dateDiff({Created Date}, ${YEARPARAMETER}, 'MM')), ' Months'))

Thanks

1 Like