emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tim Cross <theophilusx@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: org table problems with sorting of some column
Date: Fri, 31 Dec 2021 12:00:19 +1100	[thread overview]
Message-ID: <87czld4lkw.fsf@gmail.com> (raw)
In-Reply-To: <871r1tc0cm.fsf@mat.ucm.es>


Uwe Brauer <oub@mat.ucm.es> writes:

> [[S/MIME Signed Part:Undecided]]
>
>
> * Problem 1
>
> I imported this column from a CVS file, so the date format was already chosen.
>  
> |       Date |
> |------------|
> | 05.05.2020 |
> | 07.01.2021 |
> | 07.01.2021 |
> | 07.05.2020 |
> | 09.03.2021 |
> | 12.05.2020 |
> | 13.02.2020 |
> | 13.03.2020 |
> | 13.03.2020 |
> | 14.05.2020 |
> | 15.02.2021 |
> | 15.02.2021 |
> | 17.02.2020 |
> | 17.04.2020 |
> | 20.04.2020 |
> | 22.04.2020 |
> | 23.06.2020 |
> | 24.02.2021 |
> | 24.04.2020 |
> | 25.09.2020 |
> | 25.11.2020 |
>
> I'd like to sort these dates, but when I do that numerically it does not work as expected, any idea what to do.
>
>
> * Problem 2
> I'd like to order the column below descending 
>
> |   Income |
> |----------|
> |   837.00 |
> |   681.71 |
> |   664.16 |
> |   499.46 |
> |   316.64 |
> |   258.30 |
> |   258.30 |
> |   258.30 |
> |   187.52 |
> |   173.15 |
> |   170.87 |
> |   163.50 |
> |   127.76 |
> |   117.00 |
> |    94.80 |
> |    91.00 |
> | 2.852.21 |
> | 2.401.74 |
> | 1.912.16 |
> | 1.735.14 |
> | 1.480.87 |
> | 1.407.73 |
>
> But again it does not work.
>
> Any idea what to do?
>
> regards
>
> Uwe Brauer 
>
> [[End of S/MIME Signed Part]]

When reporting a problem, it would really help if you made it clear what
you have tried and how it didn't work. From your description above, it
is impossible to know if you actually tried using the built-in table
sorting command and if you did, how you used it (what input, how you
tried calling it etc). You also don't provide any details on what did
not work - was it an error, was the sorting wrong, did nothing happen at
all? There is also no details regarding your Emacs version or the org
version you are running. 

For problem 1, I suspect you will need to either change the date format
or tell org what the date format is. It won't work trying to sort
numerically as those values are not really numerical values. The date
format you currently have I think is ambiguous - in Europe it would
represent dd-mm-yyyy, but in the US it would represent mm-dd-yyyy. Best
solution would be to convert the values into an ISO format i.e.
yyyy-mm-dd.

For problem 2, I suspect the issue is because all your values are not
numerical. The value 2.852.21 might be composed of numbers, but that is
not a numerical value (what is the value of 1 + 2.852.21?). Org will
interpret those values as strings and will sort them alphabetically.

The table sorting command in the manual states

‘C-c ^’ (‘org-table-sort-lines’)
     Sort the table lines in the region.  The position of point
     indicates the column to be used for sorting, and the range of lines
     is the range between the nearest horizontal separator lines, or the
     entire table.  If point is before the first column, you are
     prompted for the sorting column.  If there is an active region, the
     mark specifies the first line and the sorting column, while point
     should be in the last line to be included into the sorting.  The
     command prompts for the sorting type, alphabetically, numerically,
     or by time.  You can sort in normal or reverse order.  You can also
     supply your own key extraction and comparison functions.  When
     called with a prefix argument, alphabetic sorting is
     case-sensitive.

Note the part on providing key extraction and comparison functions. If
you cannot convert your data to data formats org is able to recognise,
then you will need to provide functions to provide the key comparison
logic i.e. how to sort 2.99 and 2.852.21 etc.


  reply	other threads:[~2021-12-31  1:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-30 20:19 org table problems with sorting of some column Uwe Brauer
2021-12-31  1:00 ` Tim Cross [this message]
2021-12-31  8:20   ` Uwe Brauer
2021-12-31  8:25   ` Uwe Brauer
2022-01-01  0:05     ` Tim Cross

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=87czld4lkw.fsf@gmail.com \
    --to=theophilusx@gmail.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).