skip to Main Content

Im trying to perform a transformation of a coludate in QS

here is the code for calculated field

    concat(
        toString(
            extract(
                'YYYY', 
                {created_at}
            )
        ),
        toString(
            ifelse(
                extract(
                    'MM', 
                    {created_at}
                )<10,
                concat(
                    '0',
                    toString(
                        extract(
                            'MM', 
                            {created_at}
                        )
                    )
                ),
                extract(
                    'MM', 
                    {created_at}
                )
            )                     
        )
    )
)

it works if I dont use the conditional, but I need it to add a 0 when is one of the first nine months of the year.

When I try to run it, it states that the sintaxis it’s wrong and I should pick the option create, but I’m not sure what it means.

2

Answers


  1. Chosen as BEST ANSWER

    I ended up using this left(toString({created_at}), 7)

    Which left the date like yyyy-mm but works.


  2. Are you really planning to use such a complex expression?

    Why not:

    CAST (
        DATE_PART(year,created_at) * 100 + DATE_PART(month, created_at)
     AS CHAR(6)
    )
    

    ?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search