Instead of "ISNULL(SUM(ven.Quantita), 0) as PezziVenduti" use "ven.Quantita". Same for the other IsNull entries. This obviously is not what you want but you will allow you to see an extra row that you did not expect. The additional Left join is very likely causing an extra row to summed. You might be able to use one left join and use a case statement in your select to filter the sum on TipoMovimento. Hope this helps
;with Returned_And_Sold as
(
Select ID,
Type,
case when type = 'VE' then isnull(sum(M.Quantity),0) end as QuantitySold,
case when type = 'VE' then isnull(sum(M.Quantity*M.Value),0) end as TotalSold,
case when type = 'RC' then isnull(sum(M.Quantity),0) end as QuantityReturned,
case when type = 'RC' then isnull(sum(M.Quantity*M.Value),0) end as TotalReturned
from dbo.Dylog_NOL_Movimento M
where m.type in ('VE','RC')
group by ID,Type
having isnull(sum(M.Quantity), 0) <> 0
)
select
A.Shop,
A.StoreName,
S.QuantitySold,
S.TotalSold,
S.QuantityReturned,
S.TotalReturned
from Dylog_NOL_Anagrafica A
left JOIN Returned_And_Sold S on
S.ID = A.ID