# Task difference that doesn't write data in new bucket

**URL:** <https://community.influxdata.com/t/task-difference-that-doesnt-write-data-in-new-bucket/24395>\
**Category:** InfluxDB 2\
**Tags:** tasks\
**Created:** [March 24, 2022, 5:16pm UTC](https://community.influxdata.com/t/task-difference-that-doesnt-write-data-in-new-bucket/24395 "2022-03-24T17:16:42Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Juan\_Alonso\_Pla](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/juan_alonso_pla/32/9659_2.png) [@Juan\_Alonso\_Pla](https://community.influxdata.com/u/Juan_Alonso_Pla)\
**Post date:** [March 28, 2022, 8:52pm UTC](https://community.influxdata.com/t/task-difference-that-doesnt-write-data-in-new-bucket/24395/5 "2022-03-28T20:52:47Z")

</div>

I honestly see the same problem as in the other topic:

> [@Tasks works fine when started manually, but not automatically?](https://community.influxdata.com/t/tasks-works-fine-when-started-manually-but-not-automatically/24227):
>
> Hi, I’m a newbie, moving from InfluxDb 1.8 to 2.x. So I have to migrate my continuous queries to tasks. Now I have made up a Flux Task that nicely downsamples my data to hourly or daily level, and writes this to the appropriate bucket. This works all fine when I start the task by pressing the “Run Task” button in the GUI but not when the task runs according to the schedule. The log show " success" at the scheduled times, so it is run at the appropriate times, but I see no data appearing in t…

You are querying an interval of 1h (range(start: -2h, stop: -1h)) and then aggregating in intervals of 1h (aggregateWindow(every: 1h, fn: last, createEmpty: false)). The aggregateWindow function will return only **one** record for the interval especified and therefore, the difference function will not return anything since it needs **two** subsequent records to compute a difference.

If you want to get the last hour, why don’t you use:

- range(start: -2h)

and then, if aggregate by every hour:

- aggregateWindow(every: 1h, fn: last, createEmpty: false)

In this way, you will get the last value of both intervals (-2h to -1h, -1h to 0h). After doing this, if you apply difference, this will compute the difference between both intervals. This difference is the energy usage for the last hour, as you requested.

Let me know if that is what you expected. 😃

---

_[View the full topic](https://community.influxdata.com/t/task-difference-that-doesnt-write-data-in-new-bucket/24395)._
