In the future, please provide directly usable data, like this:
CREATE TABLE #data ( customer int not null, transdate date not null, transcode varchar(30) null );
INSERT INTO #data VALUES
(1, '01/13/2023', 'Data1'),
(1, '01/26/2023', 'Data2'),
(1, '01/27/2023', 'Data3'),
(1, '01/27/2023', 'WRAP-UP'),
(1, '02/10/2023', 'Data4'),
(1, '02/10/2023', 'Data5'),
(1, '02/10/2023', 'Data6'),
(1, '02/20/2023', 'WRAP-UP'),
(1, '03/22/2023', 'Data7'),
(1, '03/22/2023', 'Data8'),
(1, '03/22/2023', 'Data9'),
(1, '03/24/2023', 'Data10'),
(1, '03/30/2023', 'WRAP-UP'),
(1, '03/31/2023', 'Data11'),
(1, '04/01/2023', 'Data12')
Actual SQL code:
;WITH cte_wrap_ups AS (
SELECT customer, transdate, ROW_NUMBER() OVER(PARTITION BY customer ORDER BY transdate) AS row_num
FROM #data
WHERE transcode = 'WRAP-UP'
)
SELECT d.*, ISNULL(oa1.row_num, (SELECT MAX(row_num) + 1 FROM cte_wrap_ups)) AS [group]
FROM #data d
OUTER APPLY (
SELECT TOP (1) cwu.*
FROM cte_wrap_ups cwu
WHERE cwu.customer = d.customer AND cwu.transdate >= d.transdate
ORDER BY cwu.transdate
) AS oa1