Apply variable values in filter with entitySelector

I’m doing this same thing and am having issues with displaying as a time series on a dashboard.

timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags}
| filter isNotNull(tags)
| expand tags
| parse tags, """((LD:tag (!<<'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| fieldsAdd client = if(tag == "client", value)
| fieldsAdd environment_type = if(tag == "environment_type", value)
| fieldsAdd function = if(tag == "function", value)
| summarize {cpu = takeAny(cpu), 
  client=arrayMin(collectArray(client)),
  environment_type = arrayMin(collectArray(environment_type)),
  function = arrayMin(collectArray(function))}
  , by:{dt.entity.host}
| filter in(client, array($Client)) and 
  in(environment_type, array($Environment))

The data set comes out like this (with the tag values not shown):

The dashboard is telling my the data is not suitable for a graph:

Any help would be appreciated.