If else statement not working

Hi there, I am struggling to correct the syntax of this calculated filed. The period field is from a case statement in a custom SQL query, it is a string. I have also tried = instead of == but noting is working. Thanks in advance

ifelse(
    {Period} == '22 - 23 P1', 1,
    {Period} == '22 - 23 P2', 2,
    {Period} == '22 - 23 P3', 3,
    {Period} == '22 - 23 P4', 4,
    {Period} == '22 - 23 P5', 5,
    {Period} == '22 - 23 P6', 6,
    {Period} == '22 - 23 P7', 7,
    {Period} == '22 - 23 P8', 8,
    {Period} == '22 - 23 P9', 9,
    {Period} == '22 - 23 P10', 10,
    {Period} == '22 - 23 P11', 11,
    {Period} == '22 - 23 P12', 12,
    {Period} == '23 - 24 P1', 13,
    {Period} == '23 - 24 P2', 14,
    {Period} == '23 - 24 P3', 15,
    {Period} == '23 - 24 P4', 16,
    {Period} == '23 - 24 P5', 17,
    {Period} == '23 - 24 P6', 18,
    {Period} == '23 - 24 P7', 19,
    {Period} == '23 - 24 P8', 20,
    {Period} == '23 - 24 P9', 21,
    {Period} == '23 - 24 P10', 22,
    {Period} == '23 - 24 P11', 23,
    {Period} == '23 - 24 P12', 24,
    {Period} == '24 - 25 P1', 25,
    {Period} == '24 - 25 P2', 26,
    {Period} == '24 - 25 P3', 27,
    {Period} == '24 - 25 P4', 28,
    {Period} == '24 - 25 P5', 29,
    {Period} == '24 - 25 P6', 30,
    {Period} == '24 - 25 P7', 31,
    {Period} == '24 - 25 P8', 32,
    {Period} == '24 - 25 P9', 33,
    {Period} == '24 - 25 P10', 34,
    {Period} == '24 - 25 P11', 35,
    {Period} == '24 - 25 P12', 36,
    {Period} == '24 - 25 P13', 37,
    {Period} == '24 - 25 P14', 38,
    {Period} == '24 - 25 P15', 39,
    'NO ID'
)

Hi @JSharman,

Your ifelse function has to return the same data type for all the conditions. The “else” condition is currently returning a string but all your other conditions are returning an integer.

2 Likes

Hi @JSharman - @David_Wong is correct, please see the below link - Creating support cases and case management - AWS Support

Possibly you can return 0 as else and then change to No ID .

Regards - Sanjeeb

If you really want to show ‘NO ID’, you can change all the other values to string by enclosing them in single quotation marks.

1 Like