ZFS used space hidden in more than one snapshot

Someone was asking about this on IRC
This is mostly for myself for later:

hidden_in_snaps(){ bc -l <<<"( $(zfs list -H -p -o usedsnap ${1}) - $(zfs list -H -p -t snapshot -r -d 1 -o used ${1} | awk 'BEGIN{total=0} {total += $1} END{print total}') ) / 1024 / 1024 / 1024"; }

zfs list -H -o name | while read filesystem; do echo "$filesystem: $(hidden_in_snaps $filesystem)"; done | sort -n -k 2

The basic problem is that when you're regularly taking snapshots of a ZFS dataset where blocks are coming and going, often you'll have blocks referenced by more than 1 snapshot.
They will not be represented in the USED column of any single snapshot, but will inflate the USEDSNAP of the dataset.

If you want to know how much is being hidden from the USED column of your snapshots, you can subtract how much is used by each snapshot from the amount used by all snapshots of the dataset.

That's what the code above attempts to do. Hopefully I did it right.