Alteryx Designer Desktop Discussions

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

Highest of five columns

razzy
8 - Asteroid

Hi All,

Can someone please help me with this. from the attached excel worksheet, i need to output for every row the highest value from the five columns is there a formula i can use or a way to manipulate this using the tools.

8 REPLIES 8
Luke_C
17 - Castor

Hi @razzy 

 

Here's two ways:

 

  1. Use the MAX() function. This will work if you don't expect any new columns.
  2. Transpose the data and use a summarize to find the max for each row, then join it back to the original data.
    1. This will work for any number of new columns added in the future.

Luke_C_0-1650646114487.png

 

 

MarqueeCrew
20 - Arcturus
20 - Arcturus

@razzy ,

 

a little different approach than @Luke_C 

 

take your data directly into a summarize with max() on each of the 5 fields.  

use an APPEND FIELDS tool and put those answers into your original data.  


I'm a little sick.  

use a formula tool. 

max([field1],[field2])

 

 I'm typing this on my iPhone while at doctors.   Put all 5 fields and you'll get that max value. 

cheers,

 

 mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
razzy
8 - Asteroid

Thank you so much for responding promptly ,  how do i retain the column name for the highest value using this formula which works well and easy as an addition column.

MarqueeCrew
20 - Arcturus
20 - Arcturus

Hmmm.  What if there is a tie?

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
MarqueeCrew
20 - Arcturus
20 - Arcturus

I've asked my friend @grossal  to expand on:

 

 create a maxValue field in formula 

 

then create an if statement that checks the fields in priority order


if field = maxValue then fieldname

 

 

 he'll give you a working formula. 

cheers

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
razzy
8 - Asteroid

Yes looking at it i think that what i want can you share a workflow or the formula

Thanks

grossal
15 - Aurora
15 - Aurora

Hi Razzy,

 

thanks for tagging me Mark. I'd probably like / recommend the route that Luke started and say: Try to avoid a formula as it includes manual effort and changes in case you want to scale up.

 

If we are allowed to avoid a formula, I'd go this route:

grossal_0-1650649721512.png

 

 

It's similar to Luke solution but keeps in mind the newest information that we got from you regarding 'I also want the column name'. We start with a Record-ID to differentiate the value after the pivoting (Transpose-Tool, Key column = RecordID). After that we can simply sort by RecordID (for convenience) and Value - DESCENDING and than use a Sample tool to get the first record per RecordID (Select RecordID as a grouping column). After that we can rejoin our new information to the original (on RecordID) and we are set (I did a little renaming in the join tool to make it look nicer).

 

 

grossal_1-1650649935684.png

 

In case of a tie, this method will pick the first column name. If you'd like to have "all column that match the highest" than we need to slightly adapt it. But otherwise this method is pretty dynamic and robust for future extension and more / less columns.

 

Formula only:

If you would really really want to go full manual - what you should probably never do - you do something like this:

grossal_2-1650650335637.png

 

 

I highly recommend to avoid this at any cost.

 

 

A compromise: A little formula and a little automated:

I'd still say we should go route 1, but if you want to definitely use the max formula and make at least the part after it dynamic (to avoid to nested IF THEN ELSE over and over again), than you could do something like this:

grossal_3-1650650592554.png

 

 

It's pretty close to the 1st route, but we don't need the sort. Instead we are transposing here on two key column, our RecordID and the Highest-Value and than only use a Filter to find the rows that match the highest value, afterwards I'm using a sample to ensure that we only get one column name, otherwise we'd multiply rows when we have two values that equal the highest.

 

(I'm sitting in a train with bad WIFI right now, therefore I can't upload you the workflow, but I tried to make the description for route 1 as good as possible)

 

 

Best

Alex

razzy
8 - Asteroid

THANK YOU SO MUCH

Labels