Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-15T22:22:40.943Z
Answers.Text: Hmmm...thought I tried that already, but I'll give it another go. Thanks.
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-21T22:59:08.613Z
Answers.Text: @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?
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-15T07:25:37.667Z
Answers.LastActivityDate: 2022-12-15T07:25:37.667Z
Answers.UserDisplayName: Jalen Davenport
Body: <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>
  
Tags: <templating><group>
Title: Group/sort by multiple criteria
ThreadText: # 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](https://craftcms.com/docs/4.x/users.html#orderby) 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**: @username_1-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?  
  
  ---
  
  