add numbers down a column in OpenRefine

1.1k views Asked by At

I'd like to automatically number a column. Similar to Excel, where I can type "1" in one cell and the cells below it automatically get numbered 2, 3, 4, 5, etc. I don't know why I'm having so much trouble figuring out this function on Openrefine but any help would be greatly appreciated.

Thanks, Gail

3

There are 3 answers

3
Ettore Rizza On

You can add a new column ("Add new column based on this column") with this Grel formula inside :

row.index + 1
0
b2m On

The answer by Ettore Rizza already provides a solution for the common case. As the question author stated in a comment it does not work for his use case. He wants to add consecutive numbers to unfiltered rows.

For this you can use records. The basic idea is to create records from the filtered data and use the record index as counter.

Steps:

  1. With filters active add a new column with the expression value.
  2. Move the new column to the beginning to use it as records.
  3. With filters still active add a new column (or transform the first one) with the expression row.record.index + 1.
Original Filtered Records Index
A A A 1
1
2
B B B 2
C C C 3
0
ClaireCG On

I had the same problem as Gail. I adapted the solution provided by Benjamin and I came up with this method:

Using rows:

  1. with filters active add a new column with the expression row.index + 1
  2. in this new column, sort cell values as numbers. Then sort > reorder rows permanently (this will renumber the rows starting from 1)
  3. still in the same column: edit cells > transform... > row.index + (the number you want to start your incrementation with)

This is the best solution I found, I don't know if there is an easier way.