Let’s talk Alteryx Copilot. Join the live AMA event to connect with the Alteryx team, ask questions, and hear how others are exploring what Copilot can do. Have Copilot questions? Ask here!
Start Free Trial

Alteryx Designer Desktop Discussions

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

What is the error in this formular?

lukasjonsson
6 - Meteoroid

I keep getting "Invalid type in operator"? The [City] is of the type Int32. 

 

Any suggestions? 

10 REPLIES 10
atcodedog05
22 - Nova
22 - Nova

Hi @lukasjonsson 

 

First issue would be If block should be like.

 

If [zipcode]>1 then "a"

elseif [zipcode]>2 then "b"

else [city] endif

 

Your formula is 

 

If [zipcode]>1 then [city]="a"

elseif [zipcode]>2 then [city]="b"

else [city]=[city] endif

 

Red highlighted should be removed.

Maskell_Rascal
13 - Pulsar

Hi @lukasjonsson

 

The answer that @atcodedog05 gave is correct, but I wanted to also touch on how sometimes a one tool solution is not always the best approach. 

 

Your current approach uses just the Formula tool and should be written as follows:

Maskell_Rascal_0-1629469460059.png

 

So my input goes from this:

Maskell_Rascal_1-1629469502291.png

 

To this:

Maskell_Rascal_3-1629469562804.png

 

The output looks good and only uses one tool, so the canvas looks clean. The downside to this approach is writing out and maintaining the formula in the future. 

 

An alternative approach to this problem would be to create a text input with the zip code ranges and cities. 

 

Maskell_Rascal_4-1629469750902.png

Use a generate rows tool to get all possible zipcodes between the ranges

Maskell_Rascal_5-1629469853172.png

 

Use a Find/Replace to Append the cities to the zipcodes found and then finally using a Formula tool to bring in any unmatched records.

Maskell_Rascal_6-1629470003300.png

 

The benefit to using this approach is that it is scalable and easy to maintain for future iterations. 

 

I've attached a copy of the workflow with both approaches for you to try out. 

 

One additional thing to note on the text input file. You'll notice that København K will generate the zipcode 1300, but since Find/Replace works in sequential order Køvenhavn S will still be the output because it comes at the end of the list. 

 

Cheers!

Phil

lukasjonsson
6 - Meteoroid

Thank you for answering. Though, I still get this error message in the end at "ELSEIF [Zipcode] = 2500" saying "Invalid type of error". 

I really don't get how it differs from the other statements. 

lukasjonsson
6 - Meteoroid

@Maskell_Rascal, thank you for answering too!  Perhaps you know why I'm still having this problem?

atcodedog05
22 - Nova
22 - Nova

Hi @lukasjonsson 

 

Is it possible to provide me a sample output?

lukasjonsson
6 - Meteoroid

Hi @atcodedog05 

 

I'm pretty new in this Alteryx Comminuty, so I hope this is what you mean. Otherwise let me know. Thank you for helping, much appreciated. 

atcodedog05
22 - Nova
22 - Nova

Hi @lukasjonsson 

 

Zipcode is a string datatype hence it was creating issue. After changing it to int in select tool its working now.

 

Workflow:

atcodedog05_0-1629712559080.png

 

Hope this helps : )

atcodedog05
22 - Nova
22 - Nova

Hi @lukasjonsson 

 

Another way is too change the zipcode in formula itself to string by adding quotes.

 

Workflow:

atcodedog05_0-1629712735773.png

 

Hope this helps : )

lukasjonsson
6 - Meteoroid

Yessir! Using the select tool fixed the issue! Thank you so much 🙂 

Labels
Top Solution Authors