From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Brand Subject: Re: Table calculation Date: Sat, 20 Feb 2016 22:13:47 +0100 Message-ID: References: <87mvqvdv95.fsf@ufl.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXEqc-0006vx-0n for emacs-orgmode@gnu.org; Sat, 20 Feb 2016 16:13:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXEqb-0003vj-1w for emacs-orgmode@gnu.org; Sat, 20 Feb 2016 16:13:49 -0500 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:36868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXEqa-0003vE-Pn for emacs-orgmode@gnu.org; Sat, 20 Feb 2016 16:13:49 -0500 Received: by mail-wm0-x22c.google.com with SMTP id g62so115050521wme.0 for ; Sat, 20 Feb 2016 13:13:48 -0800 (PST) In-Reply-To: <87mvqvdv95.fsf@ufl.edu> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Brett Presnell Cc: Org Mode Hi Brett On Sat, Feb 20, 2016 at 8:41 PM, Brett Presnell wrote: > In the following table, the last row gives the number of empty cells > following the last nonempty cell in each column (except the first column > of course). I would like to create a TBLFM formula that does this > calculation for me automatically. Some time ago I tried using > org-lookup-last and org-lookup-all for this, but I never got it to work. > Any ideas/solutions? > > | Date | AA | BB | CC | DD | EE | FF | GG | HH | II | JJ | KK | LL | MM | > |--------+----+----+----+----+----+----+----+----+----+----+----+----+----| > | / | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | > | 201005 | | | | | 1 | | | 1 | | | | 1 | | > | 201008 | | | | 1 | | | | | | | | | | > | 201012 | | | | | | | | | | | | | | > | 201105 | | | | | | 1 | | | | | | | | > | 201108 | | | | | | | 1 | | | | | | | > | 201112 | | | | | | | | | | 1 | | | | > | 201205 | | | | | | | | | | | | | | > | 201208 | | | | | | | | | | | | | | > | 201212 | | | | | | | | | 1 | | | | | > | 201305 | | | 1 | | | | | 2 | | | 1 | | | > | 201308 | 1 | | | | | | | | | | | | | > | 201312 | | | | | | | | | | | | | 1 | > | 201405 | | | | | | | | 1 | | | | 1 | | > | 201408 | | 1 | | | | | | | | | | | | > | 201412 | | | | | 1 | | | | | | | | | > | 201505 | | | | 1 | | | | | | | | | | > | 201508 | | | | | | | | | 1 | | | | | > | 201512 | | | | | | | 1 | | | | | | | > | 201605 | | | | | | | | | | | | | | > |--------+----+----+----+----+----+----+----+----+----+----+----+----+----| > | | 8 | 5 | 9 | 3 | 4 | 15 | 1 | 6 | 2 | 13 | 9 | 6 | 7 | Two of the possible solutions: | Date | AA | BB | CC | DD | EE | FF | GG | HH | II | JJ | KK | LL | MM | | / | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | |--------+----+----+----+----+----+----+----+----+----+----+----+----+----| | 201005 | | | | | 1 | | | 1 | | | | 1 | | | 201008 | | | | 1 | | | | | | | | | | | 201012 | | | | | | | | | | | | | | | 201105 | | | | | | 1 | | | | | | | | | 201108 | | | | | | | 1 | | | | | | | | 201112 | | | | | | | | | | 1 | | | | | 201205 | | | | | | | | | | | | | | | 201208 | | | | | | | | | | | | | | | 201212 | | | | | | | | | 1 | | | | | | 201305 | | | 1 | | | | | 2 | | | 1 | | | | 201308 | 1 | | | | | | | | | | | | | | 201312 | | | | | | | | | | | | | 1 | | 201405 | | | | | | | | 1 | | | | 1 | | | 201408 | | 1 | | | | | | | | | | | | | 201412 | | | | | 1 | | | | | | | | | | 201505 | | | | 1 | | | | | | | | | | | 201508 | | | | | | | | | 1 | | | | | | 201512 | | | | | | | 1 | | | | | | | | 201605 | | | | | | | | | | | | | | |--------+----+----+----+----+----+----+----+----+----+----+----+----+----| | | 8 | 5 | 9 | 3 | 4 | 15 | 1 | 6 | 2 | 13 | 9 | 6 | 7 | #+TBLFM: @>$<<..@>$> = find(rev(@I..@II), 1) - 1; E Note that I moved the header separator line. When the last non-empty cell is not limited to be always 1 it gets a bit more complicated: #+TBLFM: @>$<<..@>$> = '(position-if-not (lambda (x) (equal x "")) (reverse '(@I..@II))); E Michael