calculate YTD & Prev Year YTD
<p>I want to calculate YTD (1st Jan 2016 to last date of a month) &amp; Prev year YTD (1st Jan 2015 to last date of a month) for each Client. </p>

<p>Below is the SQL Query that i have attempted, but here i get two rows for each Client instead of 1 as I'm using 'CASE WHEN'. </p>

<p>My question is how can i get the result in just one row per Client instead of one row for YTD &amp; another row for YTD-1 for each client?</p>

<pre><code>SELECT [ClientName]
, (CASE WHEN YEAR([Purchase_Date]) = YEAR(GETDATE())-1 THEN (count(Activity)) end) AS 'YTD-1'
, (CASE WHEN YEAR([Purchase_Date]) = YEAR(GETDATE()) THEN (count(Activity)) end) AS 'YTD'
FROM Purchases
WHERE MONTH([Purchase_Date]) &lt;= MONTH(GETDATE())
GROUP BY [ClientName], YEAR([Purchase_Date])
ORDER BY 1
</code></pre>

<p>Kindly Help! </p>

<p>Thanks,
Ramesh</p>