Conditional query?

I have two templated variables - one for host and other for VM. The templated variables is such that when I select the host, I get VMs in the next variable present in that host. So I will have to select the host to select the VMs.
What I want : When I select the host, I need to get values of the host and when I select VM, I need ti get VM values. I tried using OR condition but it added the values since the host variable has value in it. Is there any condition I can use in the queries ?
select value from ofstat_value where type_instance = ‘latency’ and host =~ /$host_id$/ or host =~ /$vm_id$/
I tried group by as well, it did work with latency by giving additional values (which I don’t need). For iops, the values aren’t right.
Data Source - Influxdb
Any help is appreciated.

Is there a tag you can distinguish between VMs and hosts? Then you can create a variable “hosttype” that you can use in your host variable query.

No, both are under the host tag. The relationship is through another column. Below is the part of the schema -

host =========== relation=============== type =============value

VM_1=========compute_1===============iops ============={some_value}
VM_2=========compute_1=============== latency============{some_value}
VM_3=========compute_2===============iops ============={some_value}
compute_1=====compute_all ===============iops ============={some_value}
compute_2=====compute_all=============== latency============{some_value}
compute_all=====null ====================iops ============={some_value}

But that is exactly what I said, there is another tag to distinguish them, exactly like the datacenter and host variables in the dashboard I linked to.