Here's a solution for https://www.reddit.com/r/plaintextaccounting/comments/1gd00b6/in_hledger_can_i_create_multiple_amounts_in_my:
I tested, and I see why my suggestion was wrong and gives that error:
the right side of an assignment must be a CSV field name,
and %amount is not a CSV field, so it evaluates to the empty string.
(An error message would be better perhaps.)
Here's a working conversion, still using amount
assignment. I also tweaked the account names a bit, YMMV:
a.csv:
date, Type, Asset, Amt, Spot, Memo
2024-10-09, Withdraw, USD, 17, $1.00, Withdraw to Bank
2024-10-10, Swap, TICKER, 13, $230, Swap TICKER for 230 USD
a.csv.rules:
skip 1
fields date, Type, Asset, Amt, Spot, Memo
description %Memo
account1 assets:broker:name
amount %Amt %Asset @ %Spot
if Withdraw to Bank
amount -%Amt %Asset @ %Spot
account1 assets:broker:name:USD
account2 assets:bank
if Swap .* ([^ ]+)$
account1 assets:broker:name:%Asset
account2 assets:broker:name:\1
Conversion:
$ hledger -f a.csv print
2024-10-09 Withdraw to Bank
assets:broker:name:USD -17 USD @ $1.00
assets:bank $17.00
2024-10-10 Swap TICKER for 230 USD
assets:broker:name:TICKER 13 TICKER @ $230
assets:broker:name:USD $-2990