title: SQL Server Query to Count Number of Changing Values in a Column Sequentially
body: <p>I need to count the number of changing values in a column sequentially. Please see image for illustration (correct or expected output)</p>
  
  <p>In here, the column <code>Area</code> is changing, counter column should display the sequential counter based on the changing values in area.</p>
  
  <p><a href="https://i.stack.imgur.com/esNnD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/esNnD.jpg" alt="enter image description here"></a></p>
  
  <p>I have started with this code</p>
  
  <pre><code>    SELECT a.tenant, a.area, a.date , a.gsc, f.counter
      FROM TENANT a
          inner join
              (SELECT a.tenant, COUNT(DISTINCT e.Area) AS counter
               FROM TENANT
               GROUP BY tenant
              ) AS f ON a.tenant = f.tenant
     order by a.tenant, a.date
  </code></pre>
  
  <p>And gives me this output. Counting the number of distinct values found in <code>Area</code> column IN ALL rows.</p>
  
  <p><a href="https://i.stack.imgur.com/MrWsU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MrWsU.png" alt="enter image description here"></a></p>