all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: William Henney <whenney@gmail.com>
To: Jeff Kowalczyk <jtk@yahoo.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Org Mode spreadsheet SUMIF
Date: Mon, 8 Mar 2010 09:59:03 -0600	[thread overview]
Message-ID: <41c818191003080759p2d823e5cqdf353941f1751363@mail.gmail.com> (raw)
In-Reply-To: <loom.20100308T134348-271@post.gmane.org>

Hi Jeff

On Mon, Mar 8, 2010 at 6:54 AM, Jeff Kowalczyk <jtk@yahoo.com> wrote:
> What is the Org Mode spreadsheet formula idiom for a SUMIF function?
>
> The objective is to add up the numeric values for rows matching a tag column:
>
> | 2010-03-01 | 12.2 | foo |
> | 2010-03-02 | 11.5 | foo |
> | 2010-03-02 | 12.6 | bar |
> | 2010-03-03 | 10.2 | foo |
>
> Need a total for foo: 33.9, and bar: 12.6, etc.

This is perhaps not the most elegant solution, but it does work.

|       date | values | tag | foo values | bar values |
|------------+--------+-----+------------+------------|
| 2010-03-01 |   12.2 | foo |       12.2 |          0 |
| 2010-03-02 |   11.5 | foo |       11.5 |          0 |
| 2010-03-02 |   12.6 | bar |          0 |       12.6 |
| 2010-03-03 |   10.2 | foo |       10.2 |          0 |
|------------+--------+-----+------------+------------|
|            |        |     |       33.9 |       12.6 |
  #+TBLFM: $4='(if (string-equal "$3" "foo") $2 0);L::$5='(if
(string-equal "$3" "bar") $2
0);L::@6$4=vsum(@I..@II)::@6$5=vsum(@I..@II)

The idea is to make an extra column containing only the values with a
certain tag, and then sum that. It has the advantage that there is a
natural place in the table to put each conditional sum.

You could probably avoid the need for the extra columns if you recoded
the summation using an elisp formula instead of a calc formula. As far
as I know, you can't do string comparisons inside a calc formula.

Cheers

Will

-- 

  Dr William Henney, Centro de Radioastronomía y Astrofísica,
  Universidad Nacional Autónoma de México, Campus Morelia

  reply	other threads:[~2010-03-08 15:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-08 12:54 Org Mode spreadsheet SUMIF Jeff Kowalczyk
2010-03-08 15:59 ` William Henney [this message]
2010-03-09 18:00   ` Dan Davison

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41c818191003080759p2d823e5cqdf353941f1751363@mail.gmail.com \
    --to=whenney@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jtk@yahoo.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.