Hello All, Hope all of you are doing well, I stuck in a black hole.
I cooked a dataset which having changing column count as per logic/selection. I want to sort this dataset based on some columns but these columns number is changing as shown below.
Scenario1
Scenario2
Scenario3
Scenario4
Scenario5
Column1
Column1
Column1
Column1
Column1
Column2
Sno
Column2
Column2
Column2
Column3
Column3
Sno
Column3
Column4
Column4
Column4
Column5
Sno
Column5
Column6
Sno
Sno
1 work around for this is to concatenate all columns in each scenario and create one more new column and then sort data on this new column but I am not able to implement this work around.
I tried few more things but I am not able to solve it.
Kindly help me to solve it or suggest a work around.
I assume the columns in each scenario are actual columns with data. If so, why doesn’t the Sorter node work for what you want? What kind of data do you have?
are your columns hierarchically sorted?
Do you always sort by column 1 first, then by column 2, then by column 3?
and, do you know how many columns you will have at most for sorting?
easiest solution is as follows:
use the Column Name Extractor node, second output. concat this table with a table creator node that contains blank columns equal to the maximum number of columns you expect, matching the naming patter of the columns generated by the Column Name Extractor node (second port).
this way, you will ensure that whatever amount of columns you have, the maximum will be present at all times.
then you can set up a sorter that simply sorts by ALL columns from left to right.
after that, you use a reference column filter node to get rid of all added columns again.
and in the last step, you use the column name replacer node to exchange the generic names back to your original names (you might need to transpose the top output of the Column Name Extractor for that (dont recall)).
if you are not talking about sorting the data but sorting the columns: just split of the sno column and use a Column Appender to add it back to the end.
Or the better approach if you know all column names: Reference Column Re-(Sorter)