Free Trial

Alteryx Designer Desktop Discussions

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

Dynamic Sorting of Multiple Columns

apatel1501
8 - Asteroid

Hi - i have the attached data sample with multiple years of sales and cost data. I need to be able to dynamically sort these columns on multiple fields.

 

For example: I need the output to automatically sort by Sales_P03 descending, then sales_p02, then sales_p01.  Sometimes i may have 7 or 8 sales columns and would need to sort by later periods first going back to Sales_P01 last. 

 

I know with this sample, the result is the same just sorting on Sales_p03. However, in the full actual dataset i'm working with, it will make a difference. The challenge is each data set will have varying years of data.

 

ProductNumberSales_P01Sales_P02Sales_P03Sales_P04Sales_P05COGS_P01COGS_P02COGS_P03COGS_P04COGS_P05
Product 131700.138141968.137634042.5225635836.1073627910.4923219425.5038425832.2468820804.8845622060.9785817033.61626
Product 225692.6245427151.2895526846.8242918154.4273917849.9621318770.4097622066.5043121966.8779114760.0141514660.38775
Product 313059.7597218942.4322019.4184514116.960417193.948859426.7404512831.6826815857.922359567.6030712593.84274
Product 446974.1404620392.8014218088.9987816677.79714373.9943632815.5648217422.1096216406.8644413969.2166212953.97144
Product 518337.3401619015.2596817816.132813361.3956812162.26885848.334414381.3595613993.5968410071.179249683.41652
Product 618768.2492218690.3723517179.5975414169.4113612658.636554913.1094412311.6239511400.095349286.177978374.64936
Product 74581.590414090.9846214377.114567685.393267971.52322864.291869763.6416410371.094765326.487045933.94016
Product 88574.3321611246.757611879.866445160.132125793.240965182.192146768.647797380.138033107.092763718.583
Product 918768.841215284.377510983.05412854.64158553.31811002.388059253.690836914.099437814.61445475.023
5 REPLIES 5
DylanDowrick
9 - Comet

In your example data above, you wouldn't want to download by Sales_P05 first? If it is by Sales_P03, then what criteria would you use to say that it should be sorted by 03 and not 05?

DylanDowrick
9 - Comet

Hello @apatel1501, I went ahead and assumed you meant Sales_P05, then Sales_P04, and so on. I made a macro to sort just that!

apatel1501
8 - Asteroid

Thanks! I said P03 because the data typically is like "2015, 2016, 2017, Year to Date 2016, Year to Date 2017". But i can likely drop the year to date columns and bring them back in after the sort is done and a record ID applied to keep the sort order.

 

I will check out the macro in the coming days and will accept it as solution if it works or follow up if i have any questions!

apatel1501
8 - Asteroid

This works great - thanks! The sorting primarily helps me get do a product or customer ranking so i can just drop the columns i don't need, sort using this macro, apply the rank/record ID, and then join back to the dataset to get the rank/sort.

 

I'm not too familiar with XML or batch macros so this is helpful.  Any additional resources/links to help me further understand how you got to this solution?

DylanDowrick
9 - Comet

For understanding XML (which I am mostly only aware of), you can get a start by looking at each tool's "XML View" (need to add via "Edit User Settings"). I checked out the sort tool's XML and figured if I could replace the XML of the decision piece then we could create the solution. To replace the XML in a tool you need (someone correct me if I'm wrong) a batch macro. In the upside-down question mark is the piece I've told it will update the sort tool.

XML_View_Alteryx.png

 

 

Labels
Top Solution Authors