# Influx: difference() function behaving strangely?

**URL:** <https://community.influxdata.com/t/influx-difference-function-behaving-strangely/2281>\
**Category:** Systems\
**Tags:** influxdb, influxql\
**Created:** [September 7, 2017, 2:52pm UTC](https://community.influxdata.com/t/influx-difference-function-behaving-strangely/2281 "2017-09-07T14:52:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![biren](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/biren/32/420_2.png) [@biren](https://community.influxdata.com/u/biren)\
**Post date:** [September 7, 2017, 2:52pm UTC](https://community.influxdata.com/t/influx-difference-function-behaving-strangely/2281/1 "2017-09-07T14:52:59Z")

</div>

I’m not sure what I’m doing wrong here… hoping someone here can help me with this… I feel like it should be simple…

I have field that stores the number of profiles. I have Grafana panels indicating the number of new profiles in the past minute, hour, day, and 7 days. Everything seems to work properly except the 7 days one (which _was_ working until recently).

So if I have a query like this for the “past minute” panel, it works:  
`SELECT difference(distinct("user_profiles")) FROM "data" WHERE time >= now()-2d GROUP BY time(1m)`

Keep in mind, the `now()-2d` is just a representation of the time scale set in my Grafana dashboard. The panel is also set to use the “current” value under options.

I have this same for each of the other time ranges (1h, 1d, and 7d). Up until last week, the 7d value seemed to be working just fine… but looked at my panel today and the value is wrong.

Now, if I set the where clause to `time >=now()-7d`, it works. I get the right value. In fact, setting it to 4d, 5d, 6d, or 7d works (i.e. it returns the same correct “difference”), but 3d or less causes it to return the wrong value.

Am I not “doing” the differences the right way? What’s driving me really crazy is that it was returning the right value for many days since I set this up…

Thanks for any insight!

---

<div class="post-metadata">

**Author:** ![biren](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/biren/32/420_2.png) [@biren](https://community.influxdata.com/u/biren)\
**Post date:** [September 11, 2017, 2:11pm UTC](https://community.influxdata.com/t/influx-difference-function-behaving-strangely/2281/2 "2017-09-11T14:11:45Z")

</div>

Anybody? Please? hahaha… I still can’t figure out why my “last 7 days” query won’t return the right number but 1m, 1h, and 1d do…
