Division of two metrics over time in InfluxQL

I’m visualizing the following query in Grafana:

SELECT 1 - COUNT("down_count") / (COUNT("down_count") + COUNT("up_count"))
AS "availability"
FROM (
	SELECT "value"
	AS "down_count"
	FROM "metrics"
	WHERE ("performanceLabel" = 'packetloss' AND "host" = 'server' AND "region" = '$region' AND "value" >= 80) AND $timeFilter
), (
	SELECT "value"
	AS "up_count"
	FROM "metrics"
	WHERE ("performanceLabel" = 'packetloss' AND "host" = 'server' AND "region" = '$region' AND "value" < 80) AND $timeFilter
) fill(0)

It looks at the packet loss for every server within a region and divides the down time by the up time to return a single availability percentage for whatever time interval I have selected in Grafana.

Instead of returning a single percentage, I want to return the availability grouped by time intervals so it can be graphed in a timeseries. However, when I try (for example)

SELECT 1 - COUNT("down_count") / (COUNT("down_count") + COUNT("up_count"))
AS "availability"
FROM (
	SELECT "value"
	AS "down_count"
	FROM "metrics"
	WHERE ("performanceLabel" = 'packetloss' AND "host" = 'server' AND "region" = '$region' AND "value" >= 80) AND $timeFilter GROUP BY time($__interval)
), (
	SELECT "value"
	AS "up_count"
	FROM "metrics"
	WHERE ("performanceLabel" = 'packetloss' AND "host" = 'server' AND "region" = '$region' AND "value" < 80) AND $timeFilter GROUP BY time($__interval)
) WHERE $timeFilter GROUP BY time($__interval), fill(0)

Grafana returns InfluxDB Error: only time() calls allowed in dimensions. I suspect I’ve mangled the syntax for applying the time interval grouping, but I’ve tried various versions with no success. Can anyone tell me a better way to do this, or if this is even possible?