emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* table formula, empty field, duration
@ 2020-08-06  6:24 Kristof Ralovich
  2020-09-05 13:31 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Kristof Ralovich @ 2020-08-06  6:24 UTC (permalink / raw)
  To: emacs-orgmode

Dear All,

it appears to me that the concept of "empty field" is not defined for
time durations, or it is quite different to how it is defined for
numbers (using org-mode 9.1.9).

In the first table, the empty row @6 produces an empty field for the sum
($5, first formula), that vmean is able to "skip" (second formula) and
gives the expected result 8.25 (=33/4).

#+TBLNAME: works_with_numbers
| h | start | end | h | sum |    h | h |
|---+-------+-----+---+-----+------+---|
|   |    08 |  18 |   |  10 |      |   |
|   |    11 |  15 |   |   4 |      |   |
|   |    09 |  20 |   |  11 |      |   |
|   |    10 |  18 |   |   8 |      |   |
|   |       |     |   |     |      |   |
|---+-------+-----+---+-----+------+---|
|   |       |     |   |  33 | 8.25 |   |
#+TBLFM: $5=if(typeof($3-$2)==12, string(""), $3-$2);E::@>$5=vsum(@2..@-1);
#+TBLFM: @>$6=vmean(@2$5..@-1$5);

However, in the second table, if time durations are used, how can
an empty field be represented? For an empty row @6 the current
first formula always computes 00:00 as opposed to an empty field.
Unfortunately, later, vmean includes 00:00 in the computation,
instead of skipping it. That is why the second formula produces 06:29,
instead of 08:06 for @>$6. Is there a way to force the first formula
to produce a truly empty field? Or is there a way to tell vmean to
skip 00:00 durations?

#+TBLNAME: does_not_work_with_duration
| h | start |   end | h |   sum |     h | h |
|---+-------+-------+---+-------+-------+---|
|   | 08:54 | 18:01 |   | 09:07 |       |   |
|   | 11:45 | 15:50 |   | 04:05 |       |   |
|   | 09:20 | 20:23 |   | 11:03 |       |   |
|   | 10:25 | 18:37 |   | 08:12 |       |   |
|   |       |       |   | 00:00 |       |   |
|---+-------+-------+---+-------+-------+---|
|   |       |       |   | 32:27 | 06:29 |   |
#+TBLFM: $5=if(typeof($3-$2)==12, string(""), $3-$2);EU::@>$5=vsum(@2..@-1);U
#+TBLFM: @>$6=vmean(@2$5..@-1$5);U

Thank you for your help!

Kristof



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: table formula, empty field, duration
  2020-08-06  6:24 table formula, empty field, duration Kristof Ralovich
@ 2020-09-05 13:31 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2020-09-05 13:31 UTC (permalink / raw)
  To: Kristof Ralovich; +Cc: emacs-orgmode

Hi Kristof,

Kristof Ralovich <kristof@ralovich.hu> writes:

> it appears to me that the concept of "empty field" is not defined for
> time durations, or it is quite different to how it is defined for
> numbers (using org-mode 9.1.9).
>
> In the first table, the empty row @6 produces an empty field for the sum
> ($5, first formula), that vmean is able to "skip" (second formula) and
> gives the expected result 8.25 (=33/4).
>
> #+TBLNAME: works_with_numbers
> | h | start | end | h | sum |    h | h |
>
> |---+-------+-----+---+-----+------+---|
> |   |    08 |  18 |   |  10 |      |   |
> |   |    11 |  15 |   |   4 |      |   |
> |   |    09 |  20 |   |  11 |      |   |
> |   |    10 |  18 |   |   8 |      |   |
> |   |       |     |   |     |      |   |
> |---+-------+-----+---+-----+------+---|
> |   |       |     |   |  33 | 8.25 |   |
>
> #+TBLFM: $5=if(typeof($3-$2)==12, string(""), $3-$2);E::@>$5=vsum(@2..@-1);
> #+TBLFM: @>$6=vmean(@2$5..@-1$5);

Can you provide a more minimal example?

The following table works correctly here (maint and master):

| mean1 | mean2 |
|-------+-------|
| 08:00 | 08:00 |
| 09:00 | 09:00 |
| 00:00 |       |
|-------+-------|
| 05:40 | 08:30 |
#+TBLFM: @5$1=vmean(@2..@-1);U
#+TBLFM: @5$2=vmean(@2..@-1);U

So I suspect this is something wrong with your first formula:

> #+TBLFM: $5=if(typeof($3-$2)==12, string(""), $3-$2);E

Let me know if you manage to nail down something more precise.

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-05 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06  6:24 table formula, empty field, duration Kristof Ralovich
2020-09-05 13:31 ` Bastien

Code repositories for project(s) associated with this 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).