Hi Karl > I tried to reference "the item one row up" via @@#-1$1 (and similar) > and failed. Is there a way to accomplish this as well?
It fails because @@#-1$1 is only substituted with @1-1$1, @2-1$1 etc. depending on the row it is evaluated on. To be able to use an expression as the index for an indirection one can select the element from a Calc vector or Lisp list. For a Calc formula example please e. g. look for the Calc function subscr() in http://orgmode.org/worg/org-hacks.html#field-coordinates-in-formulas Beware of the formula modifier E to keep empty fields counting for the position: | 1 | | | |---+-----+---| | 2 | 1 | 1 | | | 2 | 2 | | 4 | nan | 4 | #+TBLFM: $2 = subscr(@<$1..@>$1, @# - 1); E :: $3 = subscr(@<$1..@>$1, @# - 1) | 1st | | | |-----+-----+-----| | 2nd | 1st | 1st | | | 2nd | 2nd | | 4th | | 4th | #+TBLFM: $2 = '(nth (- @# 2) '(@<$1..@>$1)); E :: $3 = '(nth (- @# 2) '(@<$1..@>$1)) >>> [1] >>> https://github.com/novoid/org-mode-workshop/blob/master/featureshow/org-mode-teaser.org#1131-referencing-example-with-detailed-explanation >> >> Do you remember that some time ago I reminded you about a patch that I >> had sent you privately to align your above URL with the change about how >> to copy fields in the Org manual? > > A big sorry from my side: I did not process your email for too many > months. Thanks for contributing to my tutorial! Thank you for applying my patch for the section "column-based". Attached is another patch for the section "row-based" which I somehow missed in the first place. The sentence "the identity statement prevents calc from interpreting the content" that you added might be misleading because the formula is now a Lisp formula '(func ...), with a mandatory function in its first place and Calc is not involved. Btw. I failed to find a Calc formula as capable as the Lisp formula to copy content one to one. Some time ago I documented my trials into this direction in test-org-table/copy-field in testing/lisp/test-org-table.el. Michael
diff --git a/featureshow/org-mode-teaser.org b/featureshow/org-mode-teaser.org index 1d4305a..0d949ca 100644 --- a/featureshow/org-mode-teaser.org +++ b/featureshow/org-mode-teaser.org @@ -735,24 +735,24 @@ The formular can be simplified even more by using a column formula: #+NAME: comparison-table-horizontal | | Joe | Alice | Bob | sum | -| 2012 Income June | 10 | 24 | 17 | 51 | +| Income June 2012 | 10 | 24 | 17 | 51 | | plus 20 percent | 12.0 | 28.8 | 20.4 | 60.0 | | June 2013 | 11 | 31 | 21 | | | Difference | -1.0 | 2.2 | 0.6 | 1.8 | -#+TBLFM: @>$>=vsum(@5$2..@5$4)::@1$2..@1$4=remote(Income2012h, @1$$#)::@2=remote(Income2012h, @3$$#)::@3$2..@3$4=1.2 * remote(Income2012h, @3$$#);%.1f::@5$2..@5$4=@4-@3;%.1f +#+TBLFM: @>$>=vsum(@5$2..@5$4)::@1$2..@1$4='(identity remote(Income2012h, @1$$#))::@2='(identity remote(Income2012h, @3$$#))::@3$2..@3$4=1.2 * remote(Income2012h, @3$$#);%.1f::@5$2..@5$4=@4-@3;%.1f - all formulas explained in detail: - ~@>$>=vsum(@5$2..@5$4)~ - value: ~1.8~ - last column in last row (~@>$>~) is the vector-sum (~vsum~) of column two to four of fifth row (~@5$2..@5$4~) - - ~@1$2..@1$4=remote(Income2012h, @1$$#)~ + - ~@1$2..@1$4='(identity remote(Income2012h, @1$$#))~ - values: ~Joe | Alice | Bob | sum~ - column two to four of first row (~@1$2..@1$4~) are copied from the corresponding fields of the first row (~@1$$#~) of table "Income2012h" - see also [[http://orgmode.org/worg/org-hacks.html#field-coordinates-in-formulas][Org-hacks]] for field formulas - - ~@2=remote(Income2012h, @3$$#)~ + - ~@2='(identity remote(Income2012h, @3$$#))~ - values: ~2012 Income June | 10 | 24 | 17 | 51~ - the second row (~@2~) is copied from the corresponding fields of the first row (~@1$$#~) of table "Income2012h"