Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Formula tool not working for my If formula for a string value

JonaV
8 - Asteroid

Hi,

 

I would appreciate some help on this issue

 

I have a formula as follows

 

Event Year (field nam)

IF [EP_Scenario]="2019Actuals" THEN "2019" ELSE IF [EP_Scenario]="2020Actuals" THEN "2020" ELSE "" ENDIF ENDIF

 

However, when I run the workflow and check the data in the Event year field there are blanks instead of the 2019 and 2020 years that I specified in the formula. Does anybody why this is happenning?

 

Thank you,

 

JV

11 REPLIES 11
atcodedog05
22 - Nova
22 - Nova

Hi @JonaV 

 

Check the datatype set as the formula output datatype. 

 

"2020" is string

2020 is number

 

You might have set something numeric

 

You can use this instead of nested IF

 

IF [EP_Scenario]="2019Actuals" THEN "2019" ELSEIF [EP_Scenario]="2020Actuals" THEN "2020" ELSE "" ENDIF

 

 

Here is a workflow for the task.

Output:

atcodedog05_0-1604508572472.png

Workflow:

atcodedog05_2-1604508611400.png

 

Hope this helps 🙂


If this post helps you please mark it as solution. And give a like if you dont mind 😀👍

 

Jean-Balteryx
16 - Nebula
16 - Nebula

Hi @JonaV ,

 

Can you share a sample workflow ?

 

Cheers,

 

Jean-Baptiste

Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @JonaV,

 

Could you try

 

IF [EP_Scenario]="2019Actuals" THEN "2019" ELSEIF [EP_Scenario]="2020Actuals" THEN "2020" ELSE "" ENDIF

 

You're ELSE IF should be ELSEIF and you only need one ELSEIF on the end of the formula.

 

If this solves your issue then please mark the answer as correct, if not let me know!

 

Regards,

Jonathan 

Jonathan-Sherman
15 - Aurora
15 - Aurora

Or taking your nested IF function approach you'd need to use

 

IF [EP_Scenario]="2019Actuals" THEN "2019" ELSE IF [EP_Scenario]="2020Actuals" THEN "2020" ELSE "" ENDIF ELSE "" ENDIF

 

But i'd still take the first approach as I think it's simpler!

 

If this solves your issue please mark the answer as correct, if not let me know!

 

Regards,

Jonathan 

JonaV
8 - Asteroid

@atcodedog05 

The data type is right. Year is a string value not a number. I am not trying to use the Event Year field as a measure.

 

For some reason it is doing the same in other formulas as well

 

I am not sure if I should use something other than quotes ("") to specify a string within the EP_Scenario field (which is also a v_string data type)

JonaV
8 - Asteroid

Here is a snapshot

 

JonaV_0-1604508367203.png

 

atcodedog05
22 - Nova
22 - Nova

Hi @JonaV 

 

I have attached a sample workflow in the above post can you please check

atcodedog05
22 - Nova
22 - Nova

Hi @JonaV 

 

Can you provide sample data about 5-10 rows will do.

Jean-Balteryx
16 - Nebula
16 - Nebula

@JonaV , is there any spaces in values of EP_Scenario ?

 

Cheers,

 

Jean-Baptiste

Labels
Top Solution Authors