There are a few threads with examples of using custom formatters.
There are a couple of alternative methods to achieve what you want (I think). You could create a custom query using CASE WHEN, or you could use Query Builder and add a virtual column to your table (if you’re using MySQL anyway).