cancel
Showing results for 
Search instead for 
Did you mean: 

Nested If statement with current date in Hana?

Former Member
0 Kudos

Hello all,

I'm trying to create a calculated column in a Calculation View that will determine a field's value based on the current month. If it is currently January, then the value would equal 0, February would equal 1, March would equal 2, and so on. I've tried a few different ways to do this, but haven't been successful.

There isn't a datedim table I can join to this table due to uncontrollable factors, so I'm currently using another Calculated column, CurrentDate, created using the formula:

date(now())

Anyone have any suggestions? This is my current formula

IF((leftstr("CurrentMonth",3) = 'Jan'),'000', <br>IF((leftstr("CurrentMonth",3) = 'Feb'),'001',
IF((leftstr("CurrentMonth",3) = 'Mar'),'002',<br><br>IF((leftstr("CurrentMonth",3) = 'Apr'),'003',
<br>IF((leftstr("CurrentMonth",3) = 'May'),'004',<br>IF((leftstr("CurrentMonth",3) = 'Jun'),'005',
<br>IF((leftstr("CurrentMonth",3) = 'Jul'),'006',<br>IF((leftstr("CurrentMonth",3) = 'Aug'),'007',
<br>IF((leftstr("CurrenMonth",3) = 'Sep'),'008',<br>IF((leftstr("CurrentMonth",3) = 'Oct'),'009',
<br>IF((leftstr("CurrentMonth",3) = 'Nov'),'010',<br>IF((leftstr("CurrentMonth",3) = 'Dec'),'011','000'))))))))))))

I've also tried a case statement, using rightstr(leftstr(date(now()),7,2) instead of the CurrentVersion, and leftstr(daydate(now()),3) as well.

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor

Within a calculated column you can extract the current month from the current date using the COMPONENT function.

component(now(), 2)

The 2nd interface parameter of that function indicates what component of the date you wanna extract. In the example 2 means the month. The function returns an integer value for this. So at time of writing this (June) the function returns 6.

As you wanna have that January is 0, February is 1 ... you can simply reduce the returned value by 1.

component(now(), 2) - 1

Regards,
Florian

Answers (0)