14

I would like to have a column in an org mode table that is a simple monotonically increasing value, i.e. the row number such that wnen I insert and remove random rows the index value adjusts automagically. I suspect that this should be simple but it would appear I am making it way too difficult. Mind you, I am a novice at using Emacs and org mode to build spreadsheets. So a simple example spreadsheet where there are two columns, one the row index value and the other some fixed value, would be a perfect answer.

2 Answers 2

17

This example uses @# to get the row number. Similarly, $# returns the column number.

| row | data |
|-----+------|
| 2   | 0303 |
| 3   | 5123 |
| 4   | 41   |
| 5   | 4234 |
#+TBLFM: $1=@#
2
  • I tried it but got #ERROR instead of the numbers. Any idea what might be causing it?
    – M. Toya
    Jun 28, 2012 at 15:19
  • 1
    to execute the formula use C-c C-c on the "#+TBLFM: $1=@#" line Aug 22, 2016 at 14:41
10

It's often necessary, for example with descriptive rows, to start counting rows only from certain horizontal lines with 1, below for the first horizontal line: #+TBLFM: $1=vlen(@I..0). This means calculate the length of the row range from the first hline @I (the second would be @II, ...) to the current (0) row.

|bla|blabla|
|---+------|
|1  | bla  |
|2  | bla  |
#+TBLFM: $1=vlen(@I..0)

or, for above example, also simply #+TBLFM: $1=@#-1 :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.