Trying to use PHP to write 102 almost identical Excel formulas...and getting confused by the loop-in-loop construction
<p>For <code>100</code> companies, I have collected data for <code>102</code> days. I need to calculate some averages and am therefore trying to write a php script that writes the necessary <code>102</code> formulas for me, as follows:</p>

<pre><code>=AVERAGE('panel-mv3'!BP2+'panel-mv3'!BP104+'panel-mv3'!BP206 ... +'panel-mv3'!BP8876)
=AVERAGE('panel-mv3'!BP3+'panel-mv3'!BP105+'panel-mv3'!BP207 ... +'panel-mv3'!BP8877)
=AVERAGE('panel-mv3'!BP4+'panel-mv3'!BP106+'panel-mv3'!BP208 ... +'panel-mv3'!BP8878)
...
=AVERAGE('panel-mv3'!BP103+'panel-mv3'!BP205+'panel-mv3'!BP307 ... +'panel-mv3'!BP8977)
</code></pre>

<p>As you can see, horizontally the formula needs to add <code>102</code> to each <code>BP</code> cell (<code>2, 104, 206, 308, 410, etc</code>). 
So the dots (<code>...</code>) mean the formula needs to be extended with <code>+'panel-mv3'!BP308+'panel-mv3'!BP410</code> etc up untill
<code>+'panel-mv3'!BP8876</code>. In each consecutive formula, the row values shift one: <code>BP3, 105, 207, etc...</code></p>

<p>I've been trying to accomplish this using the code below, but I haven't finished it since I get confused</p>

<pre><code>for ($i = 1; $i &lt; 103; $i++) { // 102 dates
  echo "=AVERAGE(";
  for ($j = 1; $j &lt; 101; $j++) { // 100 companies
    echo "'panel-mv3'!BP" . ($i + $j) . "+";
    echo "'panel-mv3'!BP" . ($i + $j) + ($j * 102) . "+";
    echo "'panel-mv3'!BP" . ($i + 1) + (($i * 2) * 102) . ")";
  }
}
</code></pre>
