How to filter children by field, that is set in parent

<?php foreach($page->positions()->toStructure() as $group): ?>
<?= $group->position() ?>
<?php if ($page->hasChildren()): ?>
     <?php foreach($page->children()->listed() as $item): ?>
      <!-- TEAM MEMBER CONTENT -->
    <?php endforeach ?>
<? endif ?>
<? endforeach ?>

I want to show team members, grouped by positions. These positions are created in parent blueptint “People” and then displayed as query in children blueprints. So there is a list of positions in parent, and then for each team member I can select position from that list.

You can use groupBy(): https://getkirby.com/docs/reference/@/classes/cms/structure/group-by

Example usages in templates: https://getkirby.com/docs/cookbook/content/grouping-collections

Perfect, thank you! One more thing, this way the groups take order depending how children are sorted. Is it possible to first sort by groups? In my case it is structure field in parent blueprint.

Yes, you can do that, maybe do it similar to this approach here:

So you would create an array of your groups with a sorting number attached to each item, then sort by this, then group.