diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index 1e0a85f54..194c9463b 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -81,8 +81,8 @@ postingsReport opts q j = (totallabel, items) startbal | average_ opts = if historical then precedingavg else 0 | otherwise = if historical then precedingsum else 0 startnum = if historical then length precedingps + 1 else 1 - runningcalc | average_ opts = \i avg amt -> divideMixedAmount (fromIntegral i) avg + amt - avg -- running average - | otherwise = \_ bal amt -> bal + amt -- running total + runningcalc | average_ opts = \i avg amt -> avg + divideMixedAmount (fromIntegral i) (amt - avg) -- running average + | otherwise = \_ bal amt -> bal + amt -- running total totallabel = "Total" diff --git a/tests/register/average.test b/tests/register/average.test new file mode 100644 index 000000000..711f7844c --- /dev/null +++ b/tests/register/average.test @@ -0,0 +1,18 @@ +2019-1-1 + (a) 1.0 + +2019-1-2 + (a) 1 + +2019-1-3 + (a) 1 + +2019-1-4 + (a) 1 + +$ hledger -f- register -A +2019/01/01 (a) 1.0 1.0 +2019/01/02 (a) 1.0 1.0 +2019/01/03 (a) 1.0 1.0 +2019/01/04 (a) 1.0 1.0 +>=