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
// Enter your code here:
double[] numbers = {c_x, c_y, c_z};
Arrays.sort(numbers);		
out_LängeXinmm = numbers[0];
out_LängeYinmm = numbers[1];
out_LängeZinmm = numbers[2];

So, create an array with all three numbers, sort it, write it out so that X is always the smallest, Y the midlle, and Z the biggest value.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.