# Sort values from three columns by size?

I have three columns A, B, C with numerical values and I want to have the smallest value in A, the middle in B, and the largest in C.

Is there a simple way how to do that? Something like a node which can sort values over X columns from small to big?

Edit: I missed that this was to Sort Columns. I would use Group By to get the values, then transform it into sort order and use Reference Column Resorter.

Example.knwf (32.9 KB)

1 Like

Hi @robert_m_muench itâ€™s not clear to me what you are trying to do.

1. Are you asking how to get the smallest value in A, the middle in B, and the largest in C
OR
2. Are you asking how to sort the data based on the values in these columns?

Sorting is one way to get to get answers for #1 for A and C is via, but wonâ€™t necessarily work for B. And you would need to sort for each criteria you are looking for.

Just in case you want to know how to sort, The Sorter node can help you to sort:

FYI, in sorting term, â€śsmall to bigâ€ť, means ASC or Ascending order, and â€śbig to smallâ€ť would be DESC or Descending order - The sorter node offers you these options.

But if your objective is to determine thatâ€™s in #1, probably the GroupBy node is the best way to go:

The GroupBy node will allow you to get what you are looking for for #1 in one shot/execution. You simply need to apply to corresponding function as the aggregation method - check out the different functions there, it should be straight forward.

2 Likes

My first answer was basically just a GroupBy node, but then started thinking that he wanted to actually order the actual column positions in the table.

It would be easiest to show an example of the input table / desired output.

Hey @iCFO . Itâ€™s not clear to me.

From what I understand, his objective is to get â€śthe smallest value in A, the middle in B, and the largest in Câ€ť, and heâ€™s asking if there is a simply way to do this, and heâ€™s thinking that sorting is a way to go, and is asking how to sort.

But sorting is not the proper way to go really. It CAN do the job, but itâ€™s inefficient.

There is also more confusion because the title mentions sorting of values, but in reality, heâ€™s looking for a single value from each of Column A, B and C, at least thatâ€™s what I understand from the first line.

If your right, then I should have stuck with my first answer of a Group By node aggregating columns by Minimum, Median and Maximum. Sorting the column order by a calculation on the values was more fun though!

@Robster1200
yes there is
use column aggregator to aggregate a-c with sorted list as aggregation. Then just use split collection column to split the collection back to individual columns
br

Sorry, for coming back to this that late (seem I donâ€™t get any email notification when someone answers).

I solved it by using a Java Snippet node with the following code:

``````// Your custom imports:
import java.util.Arrays;

// expression start