I fixed the second code for # of annotations, you don't need the full gpm statement for that.
You use it in the template field of a "column built from other columns" (they're often referred to as composite columns).
You can also use the first one as a search if you just want it for searching purposes (instead of sorting/column icon purposes):