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

Sorting Columns by Sum of Values

williamburge
6 - Meteoroid

Hello friends, I am looking for help in sorting the fields in my data set. My data is structured as follows:

 

 

CompanyCategory 1Category 2Category 3Category 4
Product 13415
Product 214214
Product 312420
Product 425519

 

I would like to reorder the fields such that they are ordered by the sum of the values for all rows. In this example, Cat1 = 7, Cat2 = 15, Cat3 = 12, Cat4 = 68. This means the new order should be Cat4, Cat2, Cat3, Cat 1, since that puts them in descending order by sum of columns (keeping the Company field in place). My new table would like like:

 

CompanyCategory 4Category 2Category 3Category 1
Product 15413
Product 214421
Product 320241
Product 419552

 

I know that I can make these changes manually using the select tool, but is there any way to automate the process? My data has a large # of Categories and Products, so a manual solution isn't practical. I've previously been using Excel on the output to make these changes, but would prefer a native Alteryx solution

4 REPLIES 4
CharlieS
17 - Castor
17 - Castor

@williamburge

 

A solution is attached. Let me know if you have any questions.

patrick_mcauliffe
14 - Magnetar
14 - Magnetar

@williamburge

The easiest way in my opinion would be to sort the columns in the order you want them, and then feed that into a cross tab.

See attached.

Edit: looks like @CharlieS beat me to the submit button. That's a good one too.

williamburge
6 - Meteoroid

This is great - really appreciate the help. To take my question a step further, how would you go about converting this into a macro so that I have an easily replicable solution? The tricky part for me is that the # of columns/rows is variable depending on the data, and I don't know how to set up the macro input that feeds into the first transpose to account for this.

 

Thanks!

williamburge
6 - Meteoroid

Answered my own question, solution is attached if anyone needs it

Labels
Top Solution Authors