title: InfluxDB Flux - Getting last and first values as a column
body: <p>I am trying to create two new columns with the first and last values using the last() and first() functions. However the function isn’t working when I try to map the new columns. Here is the sample code below. Is this possible using Flux?</p>
  <pre><code>from(bucket: &quot;bucket&quot;)
  
    |&gt; range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |&gt; filter(fn: (r) =&gt; r[&quot;_measurement&quot;] == &quot;price_info&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;_field&quot;] == &quot;price&quot;)
    |&gt; map(fn: (r) =&gt; ({r with  
    open: last(float(v: r._value)),
    close: first(float(v: r._value)),
    })
  </code></pre>