Skip to main content
Hi,

 

 

I have an MDB file with a SourceID, its SequenceNumber and PositiveResponse as in the below image:

 

 

SourceID SeqNum PosRes

I want a new column OUTPUT having the sequence 1,2,3,4,5,...

 

But, the count should start where SeqNum=1 and PosRes=0.

 

So, it would be like-

 

SRCID SEQNR POSRES COUNT

 

5126350015700451 01 1 5

 

5126350015700451 02 1 6

 

5126350015700451 03 1 7

 

5126350015700451 04 1 8

 

5126350015700451 01 0 1

 

5126350015700451 02 0 2

 

5126350015700451 03 0 3

 

5126350015700451 04 0 4

 

 

I have tried using Sorter, Matcher, StatisticCalculator, Tester but I am not able to collect the output.

 

 

Thanks in advance.

 

Hi

 

 

Not sure I completely understand your requirement, but have a look at the Aggregator with a Group By clause.

 

 

David
I guess it's a matter of the priority of sort keys. If my understanding is correct, a workaround is:

 

Sorter: Sort the records by SourceID, PosRes, SeqNum.

 

Counter: Add the COUNT attribute to the records grouping by SourceID.

 

- Counter Name: SourceID (attribute value)

 

- Count Start: 1

 

 

If you need to restore the original order of the records, insert another Counter before the Sorter to add sequential number to every record, and finally re-sort the records by the number.
I guess it's a matter of the priority of sort keys. If my understanding is correct, a workaround is:

 

Sorter: Sort the records by SourceID, PosRes, SeqNum.

 

Counter: Add the COUNT attribute to the records grouping by SourceID.

 

- Counter Name: SourceID (attribute value)

 

- Count Start: 1

 

 

If you need to restore the original order of the records, insert another Counter before the Sorter to add sequential number to every record, and finally re-sort the records by the number.

I agree - the Sorter ought to do a lot of the work here. It might be the wrong sort priority, or maybe you need to strip the leading 0 from your seqnr, else FME might not be sorting it numerically.


I agree - the Sorter ought to do a lot of the work here. It might be the wrong sort priority, or maybe you need to strip the leading 0 from your seqnr, else FME might not be sorting it numerically.

In my observation, leading zero(s) seems to be ignored in numeric sorting with the Sorter.


Hi,

Thanks everyone.

I tried using both the ideas. Though, Sorter and Counter worked amazingly in the sequence, but what I got is a bit missing that what I want.

I got the Updated_SEQNR as the output. What I want is in the red numerics.

Actually, this is a requirement for road lanes, left and right. So, its like the number system.


How about this?

Create a new sort key attribute with the AttributeCreator with conditional value setting.


_sortkey =

If POSRES = 1 Then @Value(SEQNR)

Else -@Value(SEQNR) <-- negative of SEQNR

Sort the records by

SRCID: Alphabetic Ascending

POSRES: Numeric Descending (or NEGRES Numeric Ascending)

_sortkey: Numeric Ascending

Then, add Updated_SEQNR with a Counter.

Finally re-sort by the original record number.


Hi Takashi,

I tried your idea and its working perfectly as according to the image you shared, but The Updated_SEQNR column takes a simple count starting from 1. I didn't understand the meaning of the last two lines. Can you please suggest something on it.

Thanks


Hi Takashi,

I tried your idea and its working perfectly as according to the image you shared, but The Updated_SEQNR column takes a simple count starting from 1. I didn't understand the meaning of the last two lines. Can you please suggest something on it.

Thanks

sorry for vague. See this screenshot.

> Then, add Updated_SEQNR with a Counter.

The Counter_2 in the screenshot adds the Updated_SEQNR number to the records. The number starts from 1 for each SRCID group, since the Counter Name is set to the value of SRCID.

> Finally re-sort by the original record number.

It's optional. If you need to restore the original order of the records, add temporary record ID to every record beforehand (the 1st Counter in the screenshot), and finally re-sort the records by the record ID (the Sorter_2).


Reply