 <p>you can use ROW_NUMBER</p> <pre><code>;with cte as ( select x.pt_year, x.pt_month, x.pt_amount, y.fp_earnedprem from ( select sum(a.amount) as pt_amount , va.ACCT_YEAR as pt_year, va.ACCT_MONTHINYEAR as pt_month, ptp.PTRANS_CODE as pt_code from fact_policytransaction a join VDIM_ACCOUNTINGDATE va on a.ACCOUNTINGDATE_ID=va.ACCOUNTINGDATE_ID join DIM_POLICYTRANSACTIONTYPE ptp on a.POLICYTRANSACTIONTYPE_ID=ptp.POLICYTRANSACTIONTYPE_ID group by va.ACCT_YEAR, va.ACCT_MONTHINYEAR, ptp.PTRANS_CODE ) as x join ( select sum(fp.EARNED_PREM_AMT) as fp_earnedprem , dm.MON_YEAR as fp_year, dm.MON_MONTHINYEAR as fp_month from fact_policycoverage fp join dim_month dm on fp.MONTH_ID=dm.MONTH_ID group by dm.MON_YEAR, dm.MON_MONTHINYEAR ) as y on x.pt_year = y.fp_year and x.pt_month = y.fp_month where x.pt_year=2016 and x.pt_month=6 ) , Rn as ( select * , ROW_NUMBER() over (partition by pt_year, pt_month order by pt_year, pt_month) as RoNum from cte ) select pt_year, pt_month, pt_amount , IIF(RoNum = 1, fp_enarnedprem, 0) from Rn order by pt_year, pt_month </code></pre> <p>the main part is your own query, I only added below section and a line on top and moved order by to the bottom.</p> <pre><code>) , Rn as ( select * , ROW_NUMBER() over (partition by pt_year, pt_month order by pt_year, pt_month) as RoNum from cte ) select pt_year, pt_month, pt_amount , IIF(RoNum = 1, fp_enarnedprem, 0) from Rn order by pt_year, pt_month </code></pre>