[GNC-dev] [GNC] Reports: Help normalizing a list of gnc:monetary values

Christopher Lam christopher.lck at gmail.com
Mon Mar 29 22:05:01 EDT 2021


Hi, the simple answer is gnc:monetary/ would divide two monetary amounts
and the result is not a monetary but a simple ratio.

(define (gnc:monetary/ a b)
 (/ (gnc:gnc-monetary-amount a)
    (gnc:gnc-monetary-amount b)))

This would do the trick. Afterwards, for the chart amounts you can use the
unit-less ratio directly. Do feel free to attach your work and we'll help
you complete it.

On Mon, 29 Mar 2021, 8:00 pm Evelyn Yamanaka, <evelyn.yamanaka at gmail.com>
wrote:

> I'm trying to create a stacked bar chart graph where the total for
> each period on the x-axis is 100%, so you can easily see trends in
> changes in the proportion of individual accounts relative to the
> total.
>
> I'm using category-barchart.scm as a starting point, where account
> balances are stored as a list of pairs (<account> <balance-list>) in
> the variable all-data, and <balance-list> is a list of gnc:monetary
> values (or something like that?) for each period on the x-axis.
>
> I can get totals for each period with:
>
> (let ((totals
>         (map
>           (lambda (l) (apply gnc:monetary+ l))
>           (apply zip (map cadr all-data)))))
>   (set! all-data-totals (list "Total" totals)))
>
> However, I'm not sure how to divide gnc:monetary values by other
> gnc:monetary values. I know I can add with:
>
> (for-each
>   (lambda (d)
>     (let ((new-data (map gnc:monetary+ (cadr d) (cadr d))))
>       (set! all-data-new
>         (append all-data-new
>                 (list (car d) new-data)))))
>   all-data)
>
> But I'm not sure how to divide. Something like:
>   (map gnc:monetary/ (cadr all-data-totals) (cadr d))
>
> Of course, "gnc:monetary/" is undefined, and simply using "/" does not
> work either. Is there any way to do this? Any help would be appreciated.
>
> Thanks,
> E
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> If you are using Nabble or Gmane, please see
> https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
> -----
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.
>


More information about the gnucash-devel mailing list