title: Google Spreadsheets. How to count cells that fit a dynamic range?
body: <p>please help!</p>
  
  <p>I have a row of numeric elements.</p>
  
  <p>For each element in the row I want to count elements that meet the following equation from the row:</p>
  
  <pre><code>a*(1-d) &lt;= x &lt;= a*(1+d)
  </code></pre>
  
  <p>where:</p>
  
  <ul>
  <li><code>a</code> is the current element,</li>
  <li><code>x</code> is the comparing element,</li>
  <li><code>d</code> is a constant.</li>
  </ul>
  
  <p>COUNTIF doesn't work.</p>
  
  <pre><code>=COUNTIF($O$3:O;"&gt;=O3*(1-$B$22)"&amp;"&lt;=O3*(1+$B$22)")
  =COUNTIF($O$3:O; AND($O$3:O&gt;=O3*(1-$B$22);$O$3:O&lt;=O3*(1+$B$22))
  </code></pre>
  
  <p>As a result, I would like to see a second row where counts are stored.</p>
  
  <p>Thank you.</p>
  
  <p>My worst attempts list:)</p>
  
  <pre><code>=COUNTIF($O$3:O;"&gt;=O3*(1-$B$22)"&amp;"&lt;=O3*(1+$B$22)")
  =COUNTIF($O$3:O,&gt;O3*(1-$B$22))-COUNTIF($O$3:$O$152,&lt;O3*(1+$B$22))
  =ArrayFormula(SUMPRODUCT(AND($O$3:$O$152&gt;=O3*(1-$B$22);$O$3:$O$152&lt;=O3*(1+$B$22))))
  =DCOUNTA($O$3:$O$152, ””, &gt;1000)
  =COUNTIF($O$3:$O$152; {&gt;=O3*(1-$B$22),&lt;=O3*(1+$B$22)})
  =ArrayFormula(COUNTIF($O$3:O; AND($O$3:O&gt;=O3*(1-$B$22);$O$3:O&lt;=O3*(1+$B$22))))
  =SUM(COUNT(IF(AND($O$3:O&gt;=O3*(1-$B$22);$O$3:O&lt;=O3*(1+$B$22));1)))
  =COUNT(AND($O$3:O&gt;=O3*(1-$B$22);$O$3:O&lt;=O3*(1+$B$22)))
  </code></pre>