The solution to the problem is called catalog or sort by category (the name for the function seems to differ between versions and platforms).
Or in the words of the below quoted solution:
Sometimes, we want to combine several records in a single letter using
Word mail merge.
What it does is to include logic to mail merge, i.e.
if...then...else for finding out whether certain fields repeat.
There is a swift solution for this problem:
There is also a more detailed documentation on Microsoft's support page:
However, it seems, that it only works on Windows machines.