How can I create a column with a sequence for every new id

  • 24 November 2021
  • 1 reply

I need to create a column that counts sequentially an ID column and re-starts the counting every time the column has a new ID. Something as shown in the image, do you know if there is a way to do that?



1 reply

Userlevel 4

@glorinthegalaxy  You can do this in a Table Calculation.

Where user_id is the column with the repeated value you want an incrementing number per unique value:

if(row()=match(${order_items.user_id}, ${order_items.user_id}),1,1-1*(match(${order_items.user_id}, ${order_items.user_id})-row()))

First part is `match(${order_items.user_id}, ${order_items.user_id}`. This returns the row number of the first unique occurrence of the value in the column referenced. 

Second is if the current row is equal to that, then 1, otherwise subtract the row identifier from the first part to start the sequence again.