My `for` loop has fallen...and it can't get up I want my &lt;ul&gt; to show a single tag representing all "active" entries ( "active" using a custom lightswitch field in the entry: fellowStatus.

Each tag is a year (e.g. 2014, 2010, etc)

E.g. if there are no "active" entries with the tag 2017, it should not display.

The code block below spits out only tags where entries are "active" 
BUT...
It spits out duplicates of each tag depending on how many entries are using it. (e.g. It displays 8 instances of 2015 instead of 1)

&lt;ul&gt;
{% for entry in craft.entries.section('fellows').limit(null) %}

  {% set tags = craft.tags.relatedTo(entry).limit(1).find() %}
  {% set active = entry.fellowStatus %}

    {% if entry.fellowStatus == 0 %}

      {% for tag in tags %}
          &lt;li&gt;
            &lt;a href="{{ tag }}"&gt;{{ tag.title }}&lt;/a&gt;
          &lt;/li&gt;
      {% endfor %}

    {% endif %}

{% endfor %}
&lt;/ul&gt;
First: grab all entries that match your criteria

Second: grab all Tags related to your entries

PHP

$entryIds = Entry::find()
    -&gt;yourTagField(':notempty:')
    -&gt;fellowStatus('1')
    -&gt;section('fellows')
    -&gt;ids();
$tagsRelatedToEntries = Tag::find()
    -&gt;relatedTo($entryIds)
    -&gt;all();


Twig

{% set entryIds = craft.entries
    .section('fellows')
    .fellowStatus('1')
    .yourTagField(':notempty:')
    .ids() 
%}
{% set tags = craft.tags.relatedTo(entryIds).all() %}