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

Lookup for multiple columns against a single list of values

LJDL
6 - Meteoroid

I have a dataset similar to the sample below;

 

Data:

PersonGENDERNATIONAGEETHNICITY
10158
23138
30057
42014
53057
62118
71049
80158
93153
102029

 

I then have a separate, single lookup file setup like this;

 

Lookup:

FieldLabelDescription
GENDER0Female
GENDER1Male
GENDER3Other
NATION0UK
NATION1Other (including unknown)
AGE120 and under
AGE221 to 24
AGE325 to 29
AGE430 and over
AGE5Unknown
ETHNICITY1White
ETHNICITY2Black Caribbean
ETHNICITY3Black African
ETHNICITY4Indian
ETHNICITY5Pakinstani
ETHNICITY6Bangladeshi
ETHNICITY7Chinese
ETHNICITY8Mixed
ETHNICITY9Other
ETHNICITY10Unknown

 

Which tool(s) can I use to take the appropriate Description and replace the label in the corresponding field in the dataset? The dataset has 35 columns and there are 200+ rows in the lookup table.

 

Thanks in advance

 

John

10 REPLIES 10
Luke_C
17 - Castor
17 - Castor

Hi @LJDL 

 

This is a perfect case to use the dynamic replace tool. This tool lets you replace the data based on conditions, in this case the label. See attached example and let me know if you have any questions. 

 

Luke_C_0-1617047660418.png

 

LJDL
6 - Meteoroid

Thanks @Luke_C,

 

when I run this against my full data set I get  Error: Dynamic Replace (13): Parse Error at char(15): Invalid type in operator ==.

 

It seems to be related to the Formula tool rather than the dynamic replace, if I stick a space before the = in the formula tool the error appears in char(16) and so on.

 

I've just copied the tools from your example into my model. Any thoughts on the problem? It's reading from an xlsx file if that might cause a problem.

 

John

Luke_C
17 - Castor
17 - Castor

@LJDL there is probably a mismatch in the data types. You can use a select tool to check and fix. 

 

If i had to guess the flags in the main dataset are probably coming in as numeric, if you update to string it should work.

LJDL
6 - Meteoroid

I've tried making every field in both documents a V_String and separately a V_WString but I get the same error message either way.

pedrodrfaria
13 - Pulsar

Hi @LJDL 

 

I prefer to use the transpose and the crosstab to work with multiple columns. I find it to be much easier.

 

See the example below using your dataset:

 

pedrodrfaria_1-1617195100905.png

 

 

I found some instances where matching the columns variables did not match. For example Row 6 says GENDER = 2, but there is no Gender = 2 in the reference table. Is this correct?

 

Either way, you should get the understanding of how to approach this using the example provided below.

Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @LJDL,

 

You could also use the good old transpose attach updated descriptions and crosstab back.

 

Jonathan-Sherman_0-1617195168302.png

 

 

If this solves your issue please mark the answer as correct, if not let me know! I've attached my workflow for you to download if needed.

 

Kind regards,

Jonathan

Luke_C
17 - Castor
17 - Castor

@LJDL  my mistake, make sure the label in the lookup data is numeric, as well as the original data. 

Jonathan-Sherman
15 - Aurora
15 - Aurora

@pedrodrfaria just be wary that the join method will be case sensitive, this is something you can turn off if using the find and replace method in the technique! 😊

Jonathan-Sherman
15 - Aurora
15 - Aurora

Nice use case of the Dynamic Replace tool @Luke_C! That's one of the things I love about Alteryx - everyone can take a different approach and still get to the same answer!

Labels
Top Solution Authors