<p>You can pass multiple columns to the <a href="https://craftcms.com/docs/4.x/users.html#orderby" rel="nofollow noreferrer"><code>orderBy</code> parameter</a> like so:</p>
<pre><code>{% set people = craft.users().groupId(1).orderBy('isLeadership DESC, isActive DESC, lastname ASC').all() %}

{% for person in people %}
    {{ person.lastname }}
{% endfor %}
</code></pre>
<p>Theoretically that should give you your people sorted by leadership status, then active status, and then last name.</p>

CC BY-SA 4.0
2022-12-15T22:22:40.943Z
Hmmm...thought I tried that already, but I'll give it another go. Thanks.
4midori
CC BY-SA 4.0
2022-12-21T22:59:08.613Z
@jalen-daveport: This does not return the expected results - am getting folks where isActive = true scattered within the output, not sorted to the beginning. To clarify, both the isLeadership and isActive fields are lightswitch fields. Could I be missing something?
4midori
CC BY-SA 4.0
2022-12-15T07:25:37.667Z
2022-12-15T07:25:37.667Z
Jalen Davenport
<p>I have some users:</p>
<pre><code>{% set people = craft.users({ 
groupId:    '1',
order:      'lastname ASC' 
})
</code></pre>
<p>And two lightswitch fields associated: <strong>isLeadership</strong> and <strong>isActive</strong>.</p>
<p>This code groups users by isLeadership.</p>
<pre><code>  {% set peopleByLeadership = people|group('isLeadership')|reverse %}
  {% for isLeadership, thePeople in peopleByLeadership  %}
    {% for person in thePeople %}
      {{ person.lastname }} etc...
    {% endfor %}
  {% endfor %}
</code></pre>
<p>How do I group people first by 'isLeadership' and then by 'isActive'?</p>
<p>Results should be:</p>
<ul>
<li>Person 1 (leadership, active)</li>
<li>Person 2 (active)</li>
<li>Person 3...10 (not
active)</li>
</ul>
<p>Thanks!</p>

<templating><group>
Group/sort by multiple criteria
# Group/sort by multiple criteria

(Asked by: username_0 on 2022-12-14)

I have some users:
{% set people = craft.users({ 
groupId:    '1',
order:      'lastname ASC' 
})

And two lightswitch fields associated: isLeadership and isActive.
This code groups users by isLeadership.
  {% set peopleByLeadership = people|group('isLeadership')|reverse %}
  {% for isLeadership, thePeople in peopleByLeadership  %}
    {% for person in thePeople %}
      {{ person.lastname }} etc...
    {% endfor %}
  {% endfor %}

How do I group people first by 'isLeadership' and then by 'isActive'?
Results should be:

Person 1 (leadership, active)
Person 2 (active)
Person 3...10 (not
active)

Thanks!

**Tags:** templating, group


---

## 1 answers

### Answer by username_1 on 2022-12-15. Score: 1

You can pass multiple columns to the orderBy parameter like so:
{% set people = craft.users().groupId(1).orderBy('isLeadership DESC, isActive DESC, lastname ASC').all() %}

{% for person in people %}
    {{ person.lastname }}
{% endfor %}

Theoretically that should give you your people sorted by leadership status, then active status, and then last name.

> **Comments:**
> **username_0**: Hmmm...thought I tried that already, but I'll give it another go. Thanks.  
> **username_0**: @jalen-daveport: This does not return the expected results - am getting folks where isActive = true scattered within the output, not sorted to the beginning. To clarify, both the isLeadership and isActive fields are lightswitch fields. Could I be missing something?  

---

