If calculation is negative it shows NULL, how to fix this?
The problem is here:

(select total_count from cte where [object] = 'target')

There is not object = 'target' in the &quot;cte&quot; cte.
As the select returned null, the calculation also have to return null.
Try this: (changing cte for cte1)
with cte as (
            select 'source' [object],count(contract_id) as total_count
            FROM [account].[dbo].[account] act
            left join [account].[dbo].[contract] cont
            on act.account_id = cont.account_id)
,cte1 as(
          select 'target' [object], count(contract_id) as total_count
          from [account].[dbo].[action]
          union
          select * from cte)
          select * from cte1 
          union
          select 'diff' [object],
                 (select total_count from cte where [object] = 'source')
                -
                 (select total_count from cte1 where [object] = 'target')