diff --git a/CHANGES.md b/CHANGES.md
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -9,6 +9,12 @@
 Internal/api/developer-ish changes in the hledger-lib (and hledger) packages.
 For user-visible changes, see the hledger package changelog.
 
+# 1.24.1 2021-12-10
+
+Improvements
+
+- Added: filterQueryOrNotQuery.
+
 # 1.24 2021-12-01
 
 Improvements
diff --git a/Hledger/Query.hs b/Hledger/Query.hs
--- a/Hledger/Query.hs
+++ b/Hledger/Query.hs
@@ -23,6 +23,7 @@
   parseQueryTerm,
   simplifyQuery,
   filterQuery,
+  filterQueryOrNotQuery,
   -- * accessors
   queryIsNull,
   queryIsAcct,
@@ -378,16 +379,30 @@
 same [] = True
 same (a:as) = all (a==) as
 
--- | Remove query terms (or whole sub-expressions) not matching the given
--- predicate from this query.  XXX Semantics not completely clear.
+-- | Remove query terms (or whole sub-expressions) from this query
+-- which do not match the given predicate.
+-- XXX Semantics not completely clear.
 filterQuery :: (Query -> Bool) -> Query -> Query
 filterQuery p = simplifyQuery . filterQuery' p
+  where
+    filterQuery' :: (Query -> Bool) -> Query -> Query
+    filterQuery' p (And qs) = And $ map (filterQuery p) qs
+    filterQuery' p (Or qs) = Or $ map (filterQuery p) qs
+    filterQuery' p q = if p q then q else Any
 
-filterQuery' :: (Query -> Bool) -> Query -> Query
-filterQuery' p (And qs) = And $ map (filterQuery p) qs
-filterQuery' p (Or qs) = Or $ map (filterQuery p) qs
--- filterQuery' p (Not q) = Not $ filterQuery p q
-filterQuery' p q = if p q then q else Any
+-- | Remove query terms (or whole sub-expressions) from this query
+-- which match neither the given predicate nor that predicate negated 
+-- (eg, if predicate is queryIsAcct, this will keep both "acct:" and "not:acct:" terms).
+-- (Since 1.24.1, might be merged into filterQuery in future.)
+-- XXX Semantics not completely clear.
+filterQueryOrNotQuery :: (Query -> Bool) -> Query -> Query
+filterQueryOrNotQuery p = simplifyQuery . filterQuery' p
+  where
+    filterQuery' :: (Query -> Bool) -> Query -> Query
+    filterQuery' p (And qs)      = And $ map (filterQueryOrNotQuery p) qs
+    filterQuery' p (Or qs)       = Or  $ map (filterQueryOrNotQuery p) qs
+    filterQuery' p (Not q) | p q = Not $ filterQueryOrNotQuery p q
+    filterQuery' p q = if p q then q else Any
 
 -- * accessors
 
@@ -398,6 +413,9 @@
 queryIsNull (Not (Or [])) = True
 queryIsNull _ = False
 
+-- | Is this a simple query of this type ("depth:D") ? 
+-- Note, does not match a compound query like "not:depth:D" or "depth:D acct:A".
+-- Likewise for the following functions.
 queryIsDepth :: Query -> Bool
 queryIsDepth (Depth _) = True
 queryIsDepth _ = False
diff --git a/Hledger/Reports/MultiBalanceReport.hs b/Hledger/Reports/MultiBalanceReport.hs
--- a/Hledger/Reports/MultiBalanceReport.hs
+++ b/Hledger/Reports/MultiBalanceReport.hs
@@ -285,7 +285,7 @@
         declaredacctps = 
           [nullposting{paccount=n} | n <- journalLeafAccountNamesDeclared j
                                    , acctq `matchesAccount` n]
-          where acctq  = dbg3 "acctq" $ filterQuery queryIsAcct query
+          where acctq  = dbg3 "acctq" $ filterQueryOrNotQuery queryIsAcct query
 
     filterbydepth = case accountlistmode_ of
       ALTree -> filter ((depthq `matchesAccount`) . aname)    -- a tree - just exclude deeper accounts
diff --git a/Hledger/Utils.hs b/Hledger/Utils.hs
--- a/Hledger/Utils.hs
+++ b/Hledger/Utils.hs
@@ -59,7 +59,7 @@
 import Hledger.Utils.String
 import Hledger.Utils.Text
 import Hledger.Utils.Test
-import Data.Tree (foldTree, Tree)
+import Data.Tree (foldTree, Tree (Node, subForest))
 
 
 -- tuples
@@ -120,8 +120,11 @@
 
 -- trees
 
-treeLeaves :: Tree a -> [a]
-treeLeaves = foldTree (\a bs -> (if null bs then (a:) else id) $ concat bs)
+-- | Get the leaves of this tree as a list. 
+-- The topmost node ("root" in hledger account trees) is not counted as a leaf.
+treeLeaves :: Show a => Tree a -> [a]
+treeLeaves Node{subForest=[]} = []
+treeLeaves t = foldTree (\a bs -> (if null bs then (a:) else id) $ concat bs) t
 
 -- text
 
diff --git a/hledger-lib.cabal b/hledger-lib.cabal
--- a/hledger-lib.cabal
+++ b/hledger-lib.cabal
@@ -5,7 +5,7 @@
 -- see: https://github.com/sol/hpack
 
 name:           hledger-lib
-version:        1.24
+version:        1.24.1
 synopsis:       A reusable library providing the core functionality of hledger
 description:    A reusable library containing hledger's core functionality.
                 This is used by most hledger* packages so that they support the same
