Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Appending an empty column IF said column does not exist

elizabethmichaels91
8 - Asteroid

Hello all, I have a problem with my data blending that involves a column which may or may not be there.

 

Let me explain:

 

1. This workflow is used by many people, of which different columns may exist.

2. However, one such workflow is unable to proceed without the existance of a column, which exists in the source file of some people who use the workflow, and some source files that dont.

3. To solve this problem, I would like alteryx to 'detect' and add a null column with the said column name if it does not exist.

 

Any idea how?

Assume that the previous tool was SELECT, and the eventual connection out is to a JOIN, but that's irrelevant to the solution in my opinion.

 

Thanks again!

 

Thanks.

9 REPLIES 9
KaneG
Alteryx Alumni (Retired)

Hi @elizabethmichaels91,

 

You can do this by adding a text input with that column and then a union that on to the data. 

 

There is other ways, one being the Ensure Fields Tool in the CReW Macro Pack, and another using a Field Info tool to get a list of the fields that exist and comparing against a list, but the text input is quick and solves the problem.

 

Note: To quickly get a text input with all the fields required, look at the browse on a sample of the data that has all the fields, highlight the first row, press the copy icon and 'Selected Cells with Headers', then right click on the canvas and paste, then you can just delete that row in the text input.

 

Kane

elizabethmichaels91
8 - Asteroid

Hi Kane, thanks for your reply.

 

I tried your solution but a join will not happen if the column did not exist in the first place.

 

I solved it using an append tool with a text input instead!

 

Thank you for your help!

KaneG
Alteryx Alumni (Retired)

Hi @elizabethmichaels91,

 

Using an append tool, you will get a duplicate column if the column already exists. As you said, you can't use a Join tool, but a Union tool will stack rather than joining and so you will just get the extra column if it doesn't exist.

 

Kane

snigdhacjha
7 - Meteor

I am unable to paste just the header columns into the fields section of text input. This forces me to manually copy and paste each column name into fields.

snigdhacjha
7 - Meteor

Please discard this. solved!

Inactive User
Not applicable

can you share how did you solve this?

KaneG
Alteryx Alumni (Retired)

When copying and pasting between Browse and text input, do not use Ctrl+C/V, instead use the buttons provided in the tool

 

Copy_paste_buttons.png

 

In the above solution though, I advised to copy the first row from the browse or results window and then just right click on the canvas and paste.

 

Copy_from_browse.png

 

Then pasting on a blank canvas will create a text input tool

Paste Text input.png

snigdhacjha
7 - Meteor

Thanks a lot @KaneG. This is precisely the workaround i used. 

PoojaSingh88
7 - Meteor

How can we do this using field info

Labels