Just wanted to add few things here. User Defined Functions RU charges are based on Physical resource usage, hence you are seeing more RUs consumed. Whereas in the 2nd query, you have those individual queries which does not use the User Defined Function will have less RUs because you are just using the Where Clause and Count
Your approach of having different queries executed could be performant than having single query with UDF. Other option is to create materialized views and reading from there would be a good option as well