Is there a way to group by Report State based on the following conditions? (Currently I'm counting the number of User Stories per Report State based on the below condition table in Excel)

For a cumulative flow for something like this (excluding group-by: epic):

Is there a way to group by Report State based on the following conditions? (Currently I'm counting the number of User Stories per Report State based on the below condition table in Excel)
For a cumulative flow for something like this (excluding group-by: epic):