Single category headers in workflow templates for multiple records of same category

Say you have data like this:

With “Group by” selection in a Table view, you can easily display this in the app like so:

But what if you want to do so in a PDF file generated via a START expression in a workflow?
Use the following general model:
Which basically says “if this is the first item in this category, display a header”.

The tricky part is when using a subset of values in a table, like child values of the parent record you’re working with. Then for the second blue section, you’ll need to FILTER the whole table by a ref column, which requires the use of a _THISROW statement, and they work kind of funky inside START expressions in workflows. You’ll probably need to use _THISROW-1. Don’t really want to get into that here, but just didn’t feel like this Tip was complete without mentioning the issue.