relatedTo a category in a matrix field All, I'm very close, but missing something and any help is appreciated. I have a teamMember matrix block allowing me to add employees with some basic info. One of the fields is a category field called 'department'. I"m trying to list the departments, and within them, the employee information.

Currently my output is this: 

Marketing
  marketing member one
  marketing member two
  creative member one
  creative member two

Creative
  marketing member one
  marketing member two
  creative member one
  creative member two


However, I'm looking to achieve this:

Marketing 
  marketing member one
  marketing member two

Creative
 creative member one
 creative member two


It seems that I'm doing something wrong with relatedTo.  

My code: 

        {# Fetch entries with a Matrix block to get non empty categories #}
        {% for block in entry.teamMember.all() %}
        {% set category = block.department.one() %}

        {# Fetch entries with a Matrix block related to the category #}
        {% set entries = craft.entries.relatedTo(category).all() %}

        &lt;section id="{{ category.title }}"&gt;
            &lt;h1&gt;{{ category.title }}&lt;/h1&gt;
            {% for block in entry.teamMember.all() %}
            &lt;section class="member"&gt;
                {% set image = block.photograph.one() %}
                {% if image %}
                &lt;div style="background-image: url('{{ image.getUrl('image500') }}');"&gt;&amp;nbsp;&lt;/div&gt;
                {% endif %}

                &lt;h1&gt;{{ block.fullName }} &lt;em&gt;{{ block.jobTitle|markdown }}&lt;/em&gt;&lt;/h1&gt;
                {{ block.biography }}
            &lt;/section&gt;
            {% endfor %}

        &lt;/section&gt;
        {% endfor %}


What am I missing? Thank you in advance!
Figured it out:

    {# Fetch entries with a Matrix block to get non empty categories #}
    {% for block in entry.teamMember.all() %}
    {% set category = block.department.one() %}

    &lt;section id="{{ category.title }}"&gt;
        {% if category.title != 'Ownership' %}&lt;h1&gt;{{ category.title }}&lt;/h1&gt;{% endif %}
        {% for block in entry.teamMember.relatedTo(category).all() %}
        &lt;section class="member"&gt;
            {% set image = block.photograph.one() %}
            {% if image %}
            &lt;div style="background-image: url('{{ image.getUrl('image500') }}');"&gt;&amp;nbsp;&lt;/div&gt;
            {% endif %}

            &lt;h1&gt;{{ block.fullName }} &lt;em&gt;{{ block.jobTitle|markdown }}&lt;/em&gt;&lt;/h1&gt;
            {{ block.biography }}
        &lt;/section&gt;
        {% endfor %}

    &lt;/section&gt;
    {% endfor %}