How to change custom variable value dynamically?

Hello, I need to dynamically change Grafana custom variable based on another query variable. This is needed to plug in values into a prometheus query and it will allow to see different graphs w.r.t custom variable change.

I have the following query variables that I use for a Grafana dashboards of my service:

  • cluster_group - label_values(kube_namespace_created{namespace="$namespace"}, cluster_group)
  • cluster - label_values(kube_namespace_created{cluster_group="$cluster_group",namespace="$namespace"}, cluster)

When I open the service dashboard, cluster gets set as per cluster_group. For example, if cluster_group is set to A-1, then cluster will be set to A-1. I have A-1 and B-1 for the cluster groups and clusters of my service. And I mapped them to values of custom variables for dynamic query execution:

  • downstream_cluster_group is equal to A-1 : (X-1|Y-1|Z-1), B-1 : B-1
  • downstream_cluster - A-1 : (X-1|Y-1|Z-1|W-1), B-1 : B-1

Now I need to execute the query for a downstream service for a dashboard panel of my service in Grafana:

sum by (client_name, method) (
    downstream_service:service_requests_total:rate1m{
        prometheus="monitoring/downstream_service",
        namespace="downstream_service",
        cluster_group=~"${downstream_cluster_group}",
        cluster=~"${downstream_cluster}",
        client_name=~"my_service",
    }
)

If cluster is set to A-1 I want Grafana to set downstream_cluster_group to (X-1|Y-1|Z-1) and
downstream_cluster to (X-1|Y-1|Z-1|W-1) and so on. But simply adding custom variables as described is not sufficient and there must be another approach or a workaround to achieve the goal