Pivot without tag?

18 views
Skip to first unread message

niels...@gmail.com

unread,
Nov 28, 2022, 12:08:13 PM11/28/22
to hledger
The documentation below implies (at least to me!) that pivot can work on transactions without tags.

     FIELD can be: status, code, description, payee, note, or the full name (case insensitive) of any tag

However, would it be correct to say that there has to be a tag in a transaction for pivot to operate on that transaction? In other words, no tag, no pivoting? 

If the above is incorrect, how would you pivot on payee to show all transactions where the payee was "ACME," but there were no tags in your data file?

Many thanks for helping me understand this!

Rob

Simon Michael

unread,
Dec 6, 2022, 4:03:27 PM12/6/22
to hledger
Hi Rob,

You don't need a tag to pivot:

2022-01-01 ACME
    (a)          1

$ hledger bal -N
                   1  a
$ hledger bal -N --pivot payee
                   1  ACME

niels...@gmail.com

unread,
Dec 7, 2022, 10:40:07 AM12/7/22
to hledger
Thank you! This gets me started on what I need to learn next. 

Rob

niels...@gmail.com

unread,
Dec 7, 2022, 1:06:00 PM12/7/22
to hledger
Here is my next question: 

In your example, what do the parentheses around the "a" mean?

Here is some background information about my question, which may be helpful.

In the example below, pivot works as long as the "a" is in parentheses. 

2022-01-01 ACME
    (a)          1

However, if I remove the parentheses around "a," there is no output for the command 

hledger bal -N --pivot payee

I checked the documentation, and I was able to find examples of "(a)," and they seem to relate to valuations. However, I wasn't able to discover if that was just a coincidence. Hence my question of what the parentheses around "a" mean.

Many thanks!

Rob

Simon Michael

unread,
Dec 7, 2022, 1:32:15 PM12/7/22
to hledger

On Dec 7, 2022, at 08:06, niels...@gmail.com <niels...@gmail.com> wrote:

Here is my next question: 

In your example, what do the parentheses around the "a" mean?

They mean that this posting does not have to be balanced:

https://hledger.org/1.28/hledger.html#virtual-postings


Here is some background information about my question, which may be helpful.

In the example below, pivot works as long as the "a" is in parentheses. 

2022-01-01 ACME
    (a)          1

However, if I remove the parentheses around "a," there is no output for the command 

hledger bal -N --pivot payee

That's strange, I would expect a transaction balancing error, something like:

$ hledger bal -N --pivot payee
hledger: Error: a.j:1-2:
1 | 2022-01-01 ACME
  |     a               1

This transaction is unbalanced.
The real postings' sum should be 0 but is: 1
Consider adjusting this entry's amounts, or adding missing postings.

Are you sure the journal is like the example ? Two spaces before the 1, etc ? 


I checked the documentation, and I was able to find examples of "(a)," and they seem to relate to valuations. However, I wasn't able to discover if that was just a coincidence. Hence my question of what the parentheses around "a" mean.

Useful documentation testing! No, parentheses have nothing to do with valuation. 

I wonder how we could have made it easy to find the right doc. Perhaps a one page example showing all syntax, like the transaction diagram you made, but hyperlinked..



niels...@gmail.com

unread,
Dec 7, 2022, 2:10:58 PM12/7/22
to hledger
Sorry for the confusion about the "no output," Simon. I should have explained more.

Yes, there was an error message when I removed the parentheses, so I immediately added an extra line, as in:

2022-12-31 ACME
    a                                            1
    b

Then I ran the following command, which resulted in no output:

hledger bal -N --pivot payee

So, I don't understand why the pivot command works with a posting that doesn't need balancing versus with a balanced transaction. I am sure there is a reason, but I just am not seeing it. (More opportunity to improve my hledger knowledge!)

Also, regarding the documentation, I will have some suggested minor tweaks. However, I will need to wait to hear about the above so that I can make sure that I have a good grasp of things before I offer possible changes.

Rob

Simon Michael

unread,
Dec 7, 2022, 2:32:16 PM12/7/22
to hledger


On Dec 7, 2022, at 09:10, niels...@gmail.com <niels...@gmail.com> wrote:

Sorry for the confusion about the "no output," Simon. I should have explained more.

Yes, there was an error message when I removed the parentheses, so I immediately added an extra line, as in:

2022-12-31 ACME
    a                                            1
    b

Then I ran the following command, which resulted in no output:

hledger bal -N --pivot payee

So, I don't understand why the pivot command works with a posting that doesn't need balancing versus with a balanced transaction. I am sure there is a reason, but I just am not seeing it. (More opportunity to improve my hledger knowledge!)


I have an explanation! Look at it with print:

$ hledger --pivot payee print -x
2022-12-31 ACME
    ACME               1
    ACME              -1

Both accounts are replaced with the payee, which is the same for both so now the postings cancel out. -E reveals the zero total:

$ hledger --pivot payee bal -NE
                   0  ACME


niels...@gmail.com

unread,
Dec 7, 2022, 2:35:35 PM12/7/22
to hledger
Very helpful, and I should be able to email you my suggestions for some minor documentation changes.

Rob

Reply all
Reply to author
Forward
0 new messages