I created a ranking macro based on this community post, which can be downloaded from the Alteryx Analytics Gallery. Who doesn’t want to know what’s the best and worst within a dataset? It looked like a fun project for my first Alteryx macro. Before I dive into the macro I would like to share a couple concepts that helped me. Feel free to open the macro and see how these concepts are applied.
The Detour and Detour End tools
For all you Excel users, the Detour tool can be perceived like an IF statement. By default the Detour tool sends data through its left (L) output, but if a certain condition is met, the workflow will send data through the right (R) output. The condition can be an expression, a selection, or a checked box. Here is a simple example:
How this works:
In the Ranking macro, I utilize Detours to enable sections based on the selected Ranking types. If the user only wants Standard rankings, the section to generate Standard will run while the other sections skip to the end. The way the macro is built allows users to update or add a section without breaking another.
Include [None] in Interface Tools
Some Interface tools like the List Box and Drop Down can generate list values from connected tools. In the List Values section of a List Box or Drop Down tool, select Fields from Connected Tool. There is a check box that states Include [None]. If [None] is selected by the user, the workflow treats the field selection as empty.
In the Ranking macro, [None] is the default selection for the grouping and second ranking fields. The macro updates the direction of Detour tools based on these selections. For example, one of the Action tools inside the macro is configured as so:
How this works:
The Action tool is updating the DetourRight attribute of the Detour tool, so the DetourRight attribute should be ‘False’ when it’s empty and ‘True’ when it’s not empty. If DetourRight is ‘False’, then the Formula tool will run whereas if it’s ‘True’ then the Summarize tool will run.
These two concepts are easy to understand but can be very helpful. Other concepts used in the macro that I didn’t mention include the Dynamic Select tool, the Dynamic Rename tool, and utilizing Constants. These are great tools to begin learning.
Ranking Definitions
Now I’ll get into using the macro and the rankings. This macro ranks data on the selected field. Different ranking types handle ties and proceeding numbers accordingly. There are five types of rankings to choose from:
Additional information can be found on the Wikipedia page for Ranking.
Configuring the Ranking Macro
One or more ranking types may be selected to output in its own column.
Only a ranking field needs to be selected. The macro will rank the entire dataset on the ranking field.
By default, [None] is selected for the grouping field. Users can select a field to group assigned rankings. The assigned rankings will reset to 1 for each new group.
Ordinal rankings may require an additional field for ranking, so there is an option to rank on another field.
This shows TotalOrders sorted after UnitsSold. The ordinal ranking uses TotalOrders as an arbitrary tiebreaker.
Once again, you can download the macro from the Alteryx Analytics Gallery. I have also attached a yxzp file with fictional data. Please give the macro a try and let me know what you think!
Rithi started at Alteryx in March 2016 as a product engineer before becoming a product manager in 2019. He has worked as a business and data analyst in ecommerce and health care business intelligence utilizing Excel and SQL. Rithi lives in Denver enjoying life in the Colorado front range.
Rithi started at Alteryx in March 2016 as a product engineer before becoming a product manager in 2019. He has worked as a business and data analyst in ecommerce and health care business intelligence utilizing Excel and SQL. Rithi lives in Denver enjoying life in the Colorado front range.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.