Count number values in a template variable

I have a tag_name (node) with node ips (, etc) and i want to count the number of the exist nodes.
Is there a way to count the number of values in a template variable?

Your exact use case is not clear. I assume that InfluxDB is used, so you can use InfluxDB directly -