When you create a new custom badge adding an SQL query to make the assignment automatic, you can choose when the assignment of this badge will be triggered: