попробуйте
WITH RNKS AS (SELECT *, row_number() OVER(partition by DealerName Order By ProcessDate Desc) As RN FROM TableA),
TOPS AS (SELECT * FROM RNKS WHERE RN = 1),
DUR AS (SELECT * FROM TOPS OUTER APPLY (SELECT count (0) AS X FROM TableA A WHERE
A.processdate <= TOPS.processdate AND
A.DealerName = TOPS.DealerName AND
NOT EXISTS (
SELECT 0 FROM TABLEA A2
WHERE A2.processdate BETWEEN A.processdate AND TOPS.processdate
AND A2.DealerName = TOPS.DealerName
AND A2.BalanceType != TOPS.BalanceType)
)DQ
)
SELECT DUR.processDate,Dur.balanceType, Dur.dealerName, Dur.x as NumberConsecutive FROM DUR;
по результатам испытаний на стенде, результаты выглядят нормально
select '2019-10-20' processdate,
'Positive' BalanceType,
'Luxe' DealerName,
'20.00' balance
into TableA;
INSERT TableA values ('2019-10-21', 'Positive', 'Luxe', 20.00),
('2019-10-20', 'Positive', 'Luxe', 20.00),
('2019-10-19', 'Positive', 'Luxe', 20.00),
('2019-10-18', 'neg', 'Luxe', 20.00),
('2019-10-21', 'Positive', 'main ', 20.00),
('2019-10-20', 'neg', 'main ', 20.00),
('2019-10-19', 'Positive', 'main ', 20.00),
('2019-10-18', 'neg', 'main ', 20.00);