Total traffic for time period

I’m using influxdb as my data source. I already have data being logged that I use for bandwidth graphs (in octets and out octets for various interfaces).

I’m trying to create a singlestat panel to show how much traffic has passed in whatever interval I’m looking at. It works for the most part, then sometimes will show me a stange negative value, or just an incorrect value. I suspect it’s something off in my query that I’m overlooking.

Here’s my current query:
SELECT 1 * derivative(mean(“value”), $interval) FROM “inoctets” WHERE “host” = ‘pfsense_re1’ AND $timeFilter GROUP BY time($interval) fill(null)