title: Cypher – How to carry variables through WITH pipe
body: <p>I have the following query:</p>
  
  <pre><code>START e1=node:event(prop="0")
  MATCH e1-[r:rbel]-&gt;e2
  WITH e1, e2, count(e1) as ecount
  MATCH e1-[:redge]-&gt;p&lt;-[:redge]-e2
  WITH p.element_type as Type, p.label as Label, (count(p)*100./ecount) as percentage
  WHERE percentage &gt; 20
  RETURN Type, Label, ROUND(percentage) as Percentage
  </code></pre>
  
  <p>I am trying to calculate the percentage of times the specified pattern occurs in events with <code>prop="0"</code>, over all patterns occurring in those events.</p>
  
  <p>I receive the following error: <code>Unknown identifier 'ecount'</code></p>
  
  <p>So I replaced <code>ecount</code> in the calculation with <code>count(ecount)</code>, and that consistently  yielded <code>percentage</code>s of 100%, which I know not to be true.</p>
  
  <p>Am I going about this wrong? How can I carry the value of <code>ecount</code> to the <code>WITH</code> clause and use it in calculation?</p>
  
  <p>Any help is appreciated!</p>