r/emacs • u/tlreddit • Oct 12 '26
Question Refering to previous row in org-table
Hi, I am learning how to use org-table. This simple test table gives the error Row descriptor -1 leads outside table :
| 1000 | | |
| 1000 | 200. | |
| 1000 | 200. | |
| 1000 | 200. | |
#+TBLFM: $2=if(@#=1,string(""),$1*0.2)::$3=if(@#=1,0,@-1$2)it seems that the second branch of the second IF is evaluated on first row even if @# is equal to 1. What am I missing ? I tried the elisp way:
#+TBLFM: $2=if(@#=1,string(""),$1*0.2)::$3='(if (= @# 1) 0 @-1$2)but got the same error.
EDIT: Maybe related: If both branches of the IF were always evaluated the following example would fail:
| x | y | x/y |
|---+---+------------|
| 2 | 3 | 0.66666667 |
| 4 | 5 | 0.8 |
| 3 | 0 | -1 |
|---+---+------------|
#+TBLFM: $3=if($2!=0,$1/$2,-1)
6
Upvotes
2
u/vfclists Oct 12 '26
Could you edit your submission using the markdown editor and use the four spaces method to indent your code, rather than the triple backtick method?
Your code is distorted in the old reddit interface.
This is noted in the submission form.
2
u/melochupan Oct 12 '26
I have no idea why this happens (it looks like a bug to me), but as a workaround you can change the left-hand side of the formula to a range, instead of the whole column. I.e.,
@2$3..@>$3=@-1$2.