Sum by variable created from field in time series data

Hello. I am using a Prometheus data source to graph time series data in Grafana. One of the fields in my dataset is host_name. I’m using host_name to populate a variable named dc. For example, host_name = alpha.service.lax would add lax to the dc variable list. I need to show a request rate graph that is aggregating on dc and not host_name.

I’m struggling to come up with the right query for this. My initial guess is:

sum by (${dc}) (

rate(total_requests{dc=~"^(?:$dc)$"}[5m])

)

The error that I’m getting is:

ModifierExpr: identList: unexpected token "("; want "ident";

Any help is appreciated.