# R does not work in join.time()

**URL:** <https://community.influxdata.com/t/r-does-not-work-in-join-time/34460>\
**Category:** InfluxDB 2\
**Tags:** influxdb, query, flux\
**Created:** [June 5, 2024, 2:14am UTC](https://community.influxdata.com/t/r-does-not-work-in-join-time/34460 "2024-06-05T02:14:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@Leo](https://community.influxdata.com/u/Leo)\
**Post date:** [June 5, 2024, 2:14am UTC](https://community.influxdata.com/t/r-does-not-work-in-join-time/34460/1 "2024-06-05T02:14:18Z")

</div>

Dears

When I use left join, I find right does not work in join.time() function.

- left as below, which filed is Him  
 ![Him](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/3/387bd914b4f54a0db6d693ba00fa3ea90614a6f4.jpeg)
- rightas below, which filed is Temp  
 ![Temp](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/e/ea91c7ba24c85fde91a7cee314f6c70d615e1ab0.jpeg)
- when i try to join the values into a table on time, value of temp, the right, cant yield out.When i print out r.\_filed to check, i found what printed was “Him”, which is value of l.filed.  
 ![join](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/6/63e2439a4d79a510a5605b3113b1d3edbaedb6d2.jpeg)

code i used as below:

```auto
import "join"

raw = 
from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement")
  |> keep(columns: ["_time", "_field", "_value"])
// |> yield(name: "sort")

left = raw
  |> filter(fn: (r) => r["_field"] == "Him")

right = raw
  |> filter(fn: (r) => r["_field"] == "Temp")

join.time(method: "left", left: left, right: right, as: (l, r) => ({l with him: r._value, him_field: r._field}))
  |> yield(name: "sort")

```

could you tell me what happend?

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [June 5, 2024, 2:39pm UTC](https://community.influxdata.com/t/r-does-not-work-in-join-time/34460/2 "2024-06-05T14:39:29Z")

</div>

@Leo I think it’s because your fields have different keys, therefore the group keys of your two streams are different. Try ungrouping the `raw` stream so that the group keys match before the join.

```javascript
import "join"

raw =
    from(bucket: "bucket")
        |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
        |> filter(fn: (r) => r["_measurement"] == "measurement")
        |> keep(columns: ["_time", "_field", "_value"])
        |> group()

left =
    raw
        |> filter(fn: (r) => r["_field"] == "Him")

right =
    raw
        |> filter(fn: (r) => r["_field"] == "Temp")

join.time(method: "left", left: left, right: right, as: (l, r) => ({l with him: r._value, him_field: r._field}))
    |> yield(name: "sort")

```

However, looking at your query, I don’t think you need a join. I avoid joins whenever I can because they’re complicated and they aren’t very performant. In this case, I think pivoting on time will give you the results you’re looking for:

```auto
from(bucket: "bucket")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "measurement")
    |> keep(columns: ["_time", "_field", "_value"])
    |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")

```

---

<div class="post-metadata">

**Author:** ![Leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@Leo](https://community.influxdata.com/u/Leo)\
**Post date:** [June 6, 2024, 1:40am UTC](https://community.influxdata.com/t/r-does-not-work-in-join-time/34460/3 "2024-06-06T01:40:34Z")

</div>

pivot does work better.thank you very much. 😊
