Difference, Derivative and subquery

Has anyone used a subquery along with difference or derivative such as

SELECT difference(sum(“value”)) FROM (SELECT MAX(“value”) as value FROM “duration” WHERE $timeFilter GROUP BY bucket,api) GROUP by time(1m), bucket

The data is basically a set of buckets for times.

time    bucket  api       value
=====   ======  =======   =====

xxxx     1      /api/xxx     10
xxxx     1      /api/xxx      3
nnnn     1      /api/yyy      0
nnnn     2      /api/yyy     20

Each measurement is a counter of the number of API calls that met the bucket criteria (response time). Granted the counter can reset to 0 and I will likely use non_negative_difference but not before I can get difference, derivative or anything to work
The query w/o the difference works fine.

SELECT sum(“value”) FROM (SELECT MAX(“value”) as value FROM “duration” WHERE $timeFilter GROUP BY bucket,api) GROUP by time(1m), bucket

returns data fine and correct however:

SELECT difference(sum(“value”)) FROM (SELECT MAX(“value”) as value FROM “duration” WHERE $timeFilter GROUP BY bucket,api) GROUP by time(1m), bucket

returns an empty result set each time. Similar queries without the subquery work fine however I need to get the last value for each bucket x API and then sum them together to get the correct values to use.

Had anyone used difference with subqueries and grouping ?

Thanks,