Alteryx Designer Desktop Discussions

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

To sum data even if some columns are missing

Polite123
8 - Asteroid

Hi Team,

 

Need quick help in below data:

 

I have more than 20 columns in one data file and need to produce 21st column by adding values of those 20 columns.

But there is no certainity that all 20 columns will be present in each month data.At times we can have only 15 columns or 17 columns or all 20 columns but need to produce the additional column with all columns which are present in data file.

 

For example:

FilenameCode ACode BCode CResult
A121013
B132015
C123015

 

Result column is summation of Code A,B and C.

But in next month we might not have Code C in input file and result should be summation of Code A and B.

Similarly we might not have code A in future so result will be summation of Code B and C.

.

Absent column means no data in input file and hence result will be summation of only present column.

 

How to resolve this as I have more than 20 columns ?

Can you please help?

 

 

Thanks

 

9 REPLIES 9
Felipe_Ribeir0
16 - Nebula

Hi @Polite123 

 

One way of doing this:

 

Felipe_Ribeir0_1-1668514737789.png

 

 

DataNath
17 - Castor
17 - Castor

Hey @Polite123, after initially Transposing your data, within the aggregation configuration of the Cross-Tab tool there's an option to add a Total Column (can also add a Total Row if that's needed) and so you can do this in a couple of easy steps. As you're transposing first, this will also be fully dynamic to new fields coming in/existing fields dropping out. The Dynamic Rename at the end is a simple step to clean up the field names:

 

Add column total as part of the Cross-Tab:

 

DataNath_0-1668515113555.png

 

Final product:

 

DataNath_1-1668515119657.png

 

Thought I'd mention that, whilst it's slightly less dynamic, there is also an 'Add Totals' macro made by @MarqueeCrew and co which will do this for you with a simple tick box - you just need to tick new columns if they come in:

 

DataNath_2-1668515207370.png

 

Have attached my zipped workflow with the macro within.

Polite123
8 - Asteroid

@DataNath & @Felipe_Ribeir0 ,

 

Thank for quick reply.

Actually I am using a formula tool which does the summation operation.

 

Formula tool has Code A+ Code B +Code C.

So if Code B is not present it is giving an error.

 

 

Felipe_Ribeir0
16 - Nebula

Hi @Polite123 

 

The formula tool is not the best way to this case, since it is not dynamic (like you are seeing). The approachs using the transpose/cross tab are good ways to approach this problem.

Polite123
8 - Asteroid

@Felipe_Ribeir0 ,

 

Agreed.

 

But the issue is I dont have only one calculated field result.

I have Result A,Result B,Result C and so on based on different conditions by summing different columns.

 

Do you have any workaround for above issue?

 

Thanks

Felipe_Ribeir0
16 - Nebula

Your real input has different columns than the one that you shared at this topic? Could you share it (with dummy data)? For the one that you shared it i understand that it is doing exactly what you required:

"For example:

FilenameCode ACode BCode CResult
A121013
B132015
C123015

 

Result column is summation of Code A,B and C.

But in next month we might not have Code C in input file and result should be summation of Code A and B.

Similarly we might not have code A in future so result will be summation of Code B and C."

 

DataNath
17 - Castor
17 - Castor

@Polite123 if you have different combinations of totals that you want to add to your dataset then you can keep the suggested approach with a couple of extra steps. Let's take a couple examples where I want the total of A & C in one field, and the total of A & B in another.

 

First, I'll filter the transposed data to only leave rows relating to those fields (the other filter is the same but for A/B instead of A/C):

 

DataNath_0-1668520075705.png

 

After this, we then Cross-Tab the data as outlined in the response above:

 

DataNath_1-1668520131677.png

 

A Dynamic Select tool is used to get rid of everything other than the Total column, as well as the Filename (used for the Join at the end):

 

DataNath_2-1668520165693.png

 

The stream used for Code A&B is the same, so we get the same structure of outcome there too:

 

DataNath_3-1668520207217.png

 

Now, we just use the Join Multiple tool to bring the original dataset together, along with the varying totals - within the tool, we just remove the duplicated [Filename] field and rename the totals so it's clear which columns they're made up from:

 

DataNath_4-1668520274212.png

 

As @Felipe_Ribeir0 mentioned, this approach of first Transposing the data is fully dynamic to changes and so you can see that if we remove the Code A field in the initial data (which is used in both streams), this doesn't cause any errors in the workflow but instead it just doesn't get pulled into any calculations which we would expect:

 

DataNath_5-1668520342950.png
DataNath_6-1668520353523.png

DataNath_7-1668520366418.png

 

Hope this helps - in your case, you'd just need a Filter > Cross-Tab > Dynamic Select stream for each calculation of various field combinations you want.

KrishnaChithrathil
11 - Bolide

@Polite123 

Hola!

Please run the attached workflow and check if it's working.

KrishnaChithrathil_0-1668579639410.png

 

Edit: I didn't go through all the comments below your post.

Can you talk about the other result columns here? I mean, If you want another column Result-1, which all columns we can expect to get summed up?

I would really appreciate if you can explain the scenario once more. 

 

DenisZ
11 - Bolide

Here is my solution to the problem 

 

DenisZ_0-1668587766036.png

 

Labels
Top Solution Authors