From: Brad Knotwell <bknotwell@yahoo.com>
To: emacs-orgmode@gnu.org
Subject: TBLFM and a remote table lookup on two columns
Date: Fri, 22 Jun 2018 05:40:45 +0000 (UTC) [thread overview]
Message-ID: <1631286440.844682.1529646045252@mail.yahoo.com> (raw)
In-Reply-To: 1631286440.844682.1529646045252.ref@mail.yahoo.com
[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]
Good day all--
I've been using TBLFM and orgmode-lookup-first to conditionally update a table. It works great but I've run into something that has stumped me. Imagine I have a table like the following:
#+name: lookup_geo--------+-----+---|| T | L | Y ||--------+-----+---|| WEII | SEA | 3 || WEIII | SEA | 4 || WEIII | SJC | 3 ||--------+-----+---|
|--------+-----+-------+---------------------------------|| T | L | Count | Cost (Count * matching Y above) ||--------+-----+-------+---------------------------------|| WEIII | SJC | 3 | #ERROR || WEIII | SEA | 5 | #ERROR ||--------+-----+-------+---------------------------------|
# the TBLFM syntax below doesn't work, it's just how I would've guessed it might.
#+TBLFM: $4=`(org-lookup-first '($1 $2) '((remote(lookup_geo,@2$1..@>$1)) (remote(lookup_geo,@2$2..@>$2))) '(remote(lookup_geo,@2$3..@>$3))))
As far as I can tell, orgmode-lookup-first allows me to match the first(T) or second(L) column but it's entirely unclear how to match both. While I could workaround this with multiple tables (e.g. a separate named table/location and then have code dynamically generate the appropriate table name), a separate source block or a single key composed of two parts (e.g "WEII - SEA"; this is my current favorite workaround), I wondered if there might be a better solution.
I also considered whether it would make sense for the predicate to be given access to the entire matched row so something like the following could work:
'lambda (row) (and (= $1 (car row)) (= $2 (cadr row))))
Anyhow, is there a better way to do this beyond creating a single column that combines what was two columns?
Thx.
--Brad
[-- Attachment #2: Type: text/html, Size: 3087 bytes --]
next parent reply other threads:[~2018-06-22 5:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1631286440.844682.1529646045252.ref@mail.yahoo.com>
2018-06-22 5:40 ` Brad Knotwell [this message]
2018-06-22 6:33 ` TBLFM and a remote table lookup on two columns Thierry Banel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1631286440.844682.1529646045252@mail.yahoo.com \
--to=bknotwell@yahoo.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).