title: Count values based on both row and column condition in google spreadsheets
body: <p>I've got the following table:</p>
  <p><a href="https://i.stack.imgur.com/wl5w4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wl5w4.png" alt="enter image description here" /></a></p>
  <p>Next to that I have the following table:</p>
  <p><a href="https://i.stack.imgur.com/wilK5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wilK5.png" alt="enter image description here" /></a></p>
  <p>The value in column Q of the second table is calculated with the following function:</p>
  <pre><code>   =COUNTIF(INDEX(B:M,MATCH(P1,A:A,1),0),&quot;1&quot;)
  </code></pre>
  <p>Right not I am counting the number of 1's based on the name in column A. I however wish to expand the function to only count the cells when the column value in the first row says 'Gruul / Mag', like it does here.</p>
  <p>Does anyone know how I can get this done?</p>