title: InfluxDB 2.0 - Flux query: How to sum a column and use the sum for further calculations
body: <p>I am new to flux query language (with Influx DB 2) and cant find a solution for the following problem:</p>
  <p>I have data with changing true and false values:
  <a href="https://i.stack.imgur.com/hpaPq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hpaPq.png" alt="enter image description here" /></a></p>
  <p>I was able to calculate the time in seconds until the next change by using the events.duration function:
  <a href="https://i.stack.imgur.com/T1QnJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T1QnJ.png" alt="enter image description here" /></a></p>
  <p>Now I want to calculate the total time and the time of all &quot;false&quot;-events and after that I want to calculate the percentage of all false events. I tryed the following</p>
  <pre><code>import &quot;contrib/tomhollingworth/events&quot;
  
  total = from(bucket: &quot;********&quot;)
    |&gt; range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |&gt; filter(fn: (r) =&gt; r[&quot;_measurement&quot;] == &quot;********&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;Server&quot;] == &quot;********&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;_field&quot;] == &quot;********&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;DataNode&quot;] == &quot;********&quot;)
  
    |&gt; events.duration(
      unit: 1s,
      columnName: &quot;duration&quot;,
      timeColumn: &quot;_time&quot;,
      stopColumn: &quot;_stop&quot;
  )
    |&gt; sum(column: &quot;duration&quot;)
  
    |&gt; yield(name: &quot;total&quot;)
  
  downtime = from(bucket: &quot;********&quot;)
    |&gt; range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |&gt; filter(fn: (r) =&gt; r[&quot;_measurement&quot;] == &quot;********&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;Server&quot;] == &quot;********&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;_field&quot;] == &quot;********&quot;)
    |&gt; filter(fn: (r) =&gt; r[&quot;DataNode&quot;] == &quot;********&quot;)
  
    |&gt; events.duration(
      unit: 1s,
      columnName: &quot;duration&quot;,
      timeColumn: &quot;_time&quot;,
      stopColumn: &quot;_stop&quot;
    )
    |&gt; pivot(rowKey:[&quot;_time&quot;], columnKey: [&quot;_value&quot;], valueColumn: &quot;duration&quot;)
    |&gt; drop(columns: [&quot;true&quot;])
    |&gt; sum(column: &quot;false&quot;)
    |&gt; yield(name: &quot;downtime&quot;)
  
  downtime_percentage = downtime.false / total.duration
  </code></pre>
  <p>With this I am getting the following error  <em>error @44:23-44:31: expected {A with false:B} but found [C]</em>
  I also tryed some variations but couldnet get it to work.</p>
  <p>I guess I am getting some basic things wrong but I couldnt figure it out yet. Let me know, if you need more information.</p>