Skip to main content
Best Answer

How do I create unique ID by groups?

  • May 7, 2020
  • 5 replies
  • 141 views

max_d

Hello,

I want to create a unique numeric ID in a new attribute field from a two-letters string attribute, this way:

feature - ID

AA - 1

AB - 2

AC - 3

BA - 1

BB - 2

CA - 1

CB - 2

 

CC - 3

 

CD - 4

etc...

 

I guess I need to count how many times a letter is listed and then create IDS for every count and repeat but I don't know how to do this.

 

Many thanks,

 

Max

Best answer by bwn

As long as it is a 2 character identifier and it is the first character that resets the ID Counter every time it changes:

  1. Input to Sorter: Sort by "Feature" Ascending
  2. Then use SubstringExtractor or AttributeCreator to extract the First Letter to a new Attribute, let's call it "FirstChar"
  3. The use Counter, set the Counter Name to @Value(FirstChar)

 

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.

5 replies

fmelizard
Safer
Forum|alt.badge.img+21
  • Safer
  • May 7, 2020

Hi @max_d Is the ID based only on the 2nd character in the string?


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Best Answer
  • May 8, 2020

As long as it is a 2 character identifier and it is the first character that resets the ID Counter every time it changes:

  1. Input to Sorter: Sort by "Feature" Ascending
  2. Then use SubstringExtractor or AttributeCreator to extract the First Letter to a new Attribute, let's call it "FirstChar"
  3. The use Counter, set the Counter Name to @Value(FirstChar)

 


max_d
  • Author
  • May 8, 2020

Hi @max_d Is the ID based only on the 2nd character in the string?

HiDanatsafe, indeed, the ID is based on the first one character in the string . A,B,C,D, etc.


tomfriedl
Contributor
Forum|alt.badge.img+13
  • Contributor
  • May 8, 2020

As long as it is a 2 character identifier and it is the first character that resets the ID Counter every time it changes:

  1. Input to Sorter: Sort by "Feature" Ascending
  2. Then use SubstringExtractor or AttributeCreator to extract the First Letter to a new Attribute, let's call it "FirstChar"
  3. The use Counter, set the Counter Name to @Value(FirstChar)

 

nice idea!


max_d
  • Author
  • May 8, 2020

Thank you Bwn, it's working really well!