Skip to main content
Solved

How do I sort an attribute based on another attribute's order

  • May 30, 2019
  • 7 replies
  • 63 views

 

Column AColumn BB Sort AlphB Sort NumB Sort NatB Sort DesiredNYC51NYC1NYC1NYC11CHI1A11A11A1A51A5CHI511151111CHI5CHI11CHI1ANYC11NYCCHI

 

I'm trying to figure out how to sort column B to match column A's order. For my needs column B will not necessarily match column A but it will be a subset of column A

Best answer by takashi

I assume that you have two different source datasets - ColumnA and ColumnB, and need to sort the ColumnB features with the same criteria of the order of the ColumnA. If the assumption was correct, a possible way is:

  1. Add sequential number attribute (count) to the ColumnA features with a Counter.
  2. Add a FeatureMerger to the workspace. Send ColumnB features to the Requestor port, send ColumnA features to the Supplier port, in order to merge the count attribute from ColumnA feature to ColumnB feature having the same value as the ColumnA
  3. Sort the merged features by the count value.
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

takashi
Celebrity
  • 7843 replies
  • May 30, 2019

Looks like a value in Column B is equal to a value in Column A. That is, the Column A seems to be your desired result. Why not just use the Column A?


  • Author
  • 3 replies
  • May 31, 2019

Looks like a value in Column B is equal to a value in Column A. That is, the Column A seems to be your desired result. Why not just use the Column A?

Thank you for the response!

Sorry for the confusion, that was a poor attempt at an example. My actual columns don't match. All values in B would also be contained in A but B has duplicates that need to stay and is typically twice as large.

Actual Example:

ColumnA:NLBay,1,1A,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,KL Bay

ColumnB:3,2,32,5,36,KLBay,1A,1,23,NLBAY,20,4,22,39,28,10,27,10,29,24,14,2,34,38,4,7,26,12,16,26,14,11,30,38,1A,3,6,30,31,1,17,16,12,6,1A,8,25,35,38,NLBAY,3,1,18,29,15,33,19,35,1A,39,11,39,21,5,2,13,28,37,15,18,9,25,38,27,23,KLBAY,32,37,31,7,33,19,9,24,36,8,21,34,22,13,20,39,17,3,2,1

 

 


takashi
Celebrity
  • 7843 replies
  • Best Answer
  • May 31, 2019

I assume that you have two different source datasets - ColumnA and ColumnB, and need to sort the ColumnB features with the same criteria of the order of the ColumnA. If the assumption was correct, a possible way is:

  1. Add sequential number attribute (count) to the ColumnA features with a Counter.
  2. Add a FeatureMerger to the workspace. Send ColumnB features to the Requestor port, send ColumnA features to the Supplier port, in order to merge the count attribute from ColumnA feature to ColumnB feature having the same value as the ColumnA
  3. Sort the merged features by the count value.

Forum|alt.badge.img
  • 104 replies
  • May 31, 2019

This should work:

Let a Sampler retrieve the first of each unique value of Column A and output the samples to a Counter. Let your source also directly enter a FeatureMerger as Requestor and let the Counter come in as Supplier. Output Merged and UnmergedRequestor to a Sorter that sorts Column B by _count. And you should be... eh, sorted.


Forum|alt.badge.img
  • 104 replies
  • May 31, 2019

This should work:

Let a Sampler retrieve the first of each unique value of Column A and output the samples to a Counter. Let your source also directly enter a FeatureMerger as Requestor and let the Counter come in as Supplier. Output Merged and UnmergedRequestor to a Sorter that sorts Column B by _count. And you should be... eh, sorted.

@takashi beat me to it. :-) Also note that my Sampler is unneccesary if your Column A only contains unique values, which I'm guessing it does. It might actually be unneccesary anyway, unless Column A has huge amounts of values.


  • Author
  • 3 replies
  • May 31, 2019

I assume that you have two different source datasets - ColumnA and ColumnB, and need to sort the ColumnB features with the same criteria of the order of the ColumnA. If the assumption was correct, a possible way is:

  1. Add sequential number attribute (count) to the ColumnA features with a Counter.
  2. Add a FeatureMerger to the workspace. Send ColumnB features to the Requestor port, send ColumnA features to the Supplier port, in order to merge the count attribute from ColumnA feature to ColumnB feature having the same value as the ColumnA
  3. Sort the merged features by the count value.

That solution works flawlessly. Thank you Takashi!!


  • Author
  • 3 replies
  • May 31, 2019

@takashi beat me to it. :-) Also note that my Sampler is unneccesary if your Column A only contains unique values, which I'm guessing it does. It might actually be unneccesary anyway, unless Column A has huge amounts of values.

I still appreciate the feedback. Thank you very much for your help. It works perfectly