Aggregation of consecutive date ranges

Hi Jefferson and welcome to the Community!

First of all, thanks for an example with sample data and expected outcome. That made the question much easier to understand.

I believe the most tricky part here is identifying consecutive stays. Once we can band consecutive stays together, we can aggregate easily.

As per your comment in the workbook, stays are consecutive when the Ward Type is the same and the Start Date of the subsequent Ward Stay is on the same day. Apparently, patient ID doesn’t change during a consecutive stay.

In EasyMorph comparison with previous rows is done using the “Shift columns” action that can bring previous row values one level down as a new column, then comparing values with this new column.

With a few rules, we can identify consecutive stays. Aggregating them is the easiest part.

See below a project that does the transformation you need. I’ve left comments with explanations to some actions.

wards.morph (7.9 KB)

**** topic subject changed to a more descriptive one