# Import flux libraries inside tasks

**URL:** <https://community.influxdata.com/t/import-flux-libraries-inside-tasks/31322>\
**Category:** InfluxDB 2\
**Tags:** flux, tasks\
**Created:** [August 29, 2023, 10:11am UTC](https://community.influxdata.com/t/import-flux-libraries-inside-tasks/31322 "2023-08-29T10:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardosgeral](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ricardosgeral/32/13981_2.png) [@Ricardosgeral](https://community.influxdata.com/u/Ricardosgeral)\
**Post date:** [August 29, 2023, 10:11am UTC](https://community.influxdata.com/t/import-flux-libraries-inside-tasks/31322/1 "2023-08-29T10:11:02Z")

</div>

Hi

I want to create a task that collects data from a bucket, do some maths and put it in another bucket.

The problem is that I need to perform a sin() function  
Apparently `import "math"` does not seem to work inside task

This is what i have

```auto
// Task options
option task = {name: "displacement_results", every: 10s, offset: 0m}

import "math"

// Data source
    from(bucket: "telegraf")
        |> range(start: -task.every)
        |> filter(fn: (r) => r["_measurement"] == "I1")
        |> filter(fn: (r) => int(v: r.n) > 0)
        |> filter(fn: (r) => r["_field"] == "aX")

        // Data processing
        |> map(fn: (r) => ({r with n: r.n, level: -0.5 + 0.5 * float(v: r["n"])}))
        // new column with displacement calculated from angle
        |> map(fn: (r) => ({r with _value: r._value, dX: 0.5 * math.sin(x: r._value / 180.0 * 3.1415926)}))
        |> map(fn: (r) => ({r with dX: r.dX, cummulative_dX: r.dX}))
        |> to(bucket: "results")

```

SO, how can I import the trigonometric functions to use alongside with flux in Task?

best regards

---

<div class="post-metadata">

**Author:** ![AlexR](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@AlexR](https://community.influxdata.com/u/AlexR)\
**Post date:** [March 19, 2024, 11:52pm UTC](https://community.influxdata.com/t/import-flux-libraries-inside-tasks/31322/2 "2024-03-19T23:52:28Z")

</div>

Ran into the same problem. But [this ticket](https://community.influxdata.com/t/how-to-import-some-variables-in-my-task/20708/3) helped:

The imports must appear on the very top of the task script, before `option task = ...`

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [March 21, 2024, 8:00pm UTC](https://community.influxdata.com/t/import-flux-libraries-inside-tasks/31322/3 "2024-03-21T20:00:06Z")

</div>

@AlexR thank you for sharing! @Ricardosgeral did that suggestion help you?

---

<div class="post-metadata">

**Author:** ![Ricardosgeral](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ricardosgeral/32/13981_2.png) [@Ricardosgeral](https://community.influxdata.com/u/Ricardosgeral)\
**Post date:** [March 21, 2024, 8:20pm UTC](https://community.influxdata.com/t/import-flux-libraries-inside-tasks/31322/4 "2024-03-21T20:20:58Z")

</div>

Hi @Anaisdg its did help
