How to get the sequence for a group of values

Like how to get AddressNO group by the same IDs like below?
image

If I understand your question, you’re trying to group your data set by the AddressNO field. That is, the expected output would have all rows with AddressNO equal to one grouped, and all AddressNO equal to two grouped, etc.

If that’s the case, then you’ll need to sort on AddressNO and then use a group by field snap.

Here is the pipeline in my example if you want to upload it and try it out.

groupby-example_2018_10_25.slp (5.1 KB)

Yes, I can do a group by, but what I want is to provide the sequence for the rows in one group. The source file only have IDs and address, how to get addressno?

Oh, sorry for the misunderstanding. You want to generate the AddressNO based on the number of elements for each ID?

You’ll have to modify the sort and group by to do so by ID. Then afterwards you’ll need a Mapper snap using the map expression.

$group.map((e, index) => e.extend({'AddressNO': index + 1}))

For each element that was group, this will extend it with the index in the group array.

Finally now that the elements have an AddressNO you can split everything back out using the JSONSplitter snap.

I’ve updated the pipeline so you can try it out yourself.

groupby-example_2018_10_26.slp (8.0 KB)

1 Like

Thanks, it’s work

A post was split to a new topic: SOAP Customize Envelope