Value based on Running sum - need to resort results

We have created a text value based on a running sum which assigns a 1 each time the selected service is populated and a 0 for any other services on the same patient. This report assigns “Exclude” for all rows with runningsum = 0 and assigns “Include” for rows with runningsum greater than or equal to 1. After the include/exclude field is populated via a variable, we need to resort based on the service field so we can create breaks. This changes our original include/exclude assignments because the sort changes. Is there a way to fix this.
Selected service = primary
Data:
service flag runningsum (flag) incl/excl date

Pre-svc 0 0 EXCLUDE 12/31/2020
Primary 1 1 INCLUDE 1/1/2021
Secondary 0 1 INCLUDE 1/2/2021
Primary 1 2 INCLUDE 1/5/2021
Secondary 0 2 INCLUDE 1/6/2021

We need to ensure that the assigned include/exclude remains fixed so we can resort the data without losing these assigned values.
We want to provide break s at the service level with all other information remaining in tact.

Flag = 0 or 1
Running sum is next to that field, etc.

Changing the sort and/or break is going to change the running sum result. There is the reset option for the function, but that’s not going to work for what you described.

You’ll need to change your approach and use calculation contexts. Maybe something along the lines of finding the min service date where service is primary in patient id. Then compare your service date to that min value to determine if you should show or hide the row.