I have a relationship field which contains a number of different pieces of content.

Each piece of content has a type property.

Is there anyway I can count the number of each of the types that is included in the relationship.

For example.  3 Product related items, and 2 Showcase related items.

I need to be able to get the {total_results} of each type. 

This is what I'm trying to do...

 {if "{related:panel_type}" == "products"}

      {if "{related:count}" == "1"}
        &lt;ul class="p"&gt;
      {/if}
        // do stuff 
      {if "{related:count}" == "{related:total_results}"}
        &lt;/ul&gt;
      {/if}

    {/if}

  {if "{related:panel_type}" == "showcase"}

      {if "{related:count}" == "1"}
        &lt;ul class="s"&gt;
      {/if}
        // do stuff 
      {if "{related:count}" == "{related:total_results}"}
        &lt;/ul&gt;
      {/if}

    {/if}


So at the moment {total_results} is equal to 5 so my ul is not getting closed properly.

Does anyone have any ideas how I can get around this problem.

I would like to keep my markup inside the exp:channel:entries loop, and ideally use only one loop.

Any help, greatly appreciated 


Question: How can I learn how to lay out an "evidence scene"?
Answer: I can't post this as a comment, but I feel like it's worthy of an answer anyway. it expands on what Bankuei answered about pre-planned scenes. 

Be flexible in your plot

If at all possible, allow the investigators to go at a faster pace than you accounted for. Maybe they figured out where the criminals will strike next before you expected them to, even before the criminals actually strike there. Maybe they decyphered what the big bad is up to at such an early time that they get there before he actually starts a crucial part of his master plan. In that case, avoid the temptation of slowing them down by throwing a couple of not-so-random encounters at them. Players like to think they outsmarted the GM, but don't like it if the GM punishes them for it.

Instead, allow them to halt the big bad before he even gets going. Or let them warn the town watch about the criminals, or even let them go after them themselves. Then, when they're patting themselves on the shoulder, PLOT TWIST! The party gets arrested by the town watch because the watch doesn't know that the esteemed noble is actually a demon. Or the criminals get bailed out and immediately attack the party at their inn.

Or the party is actually completely wrong in their clues. This is a goldmine. Go with the flow. Let the party think they caught a major criminal, while they actually caught a petty thief with no relation to the plot. They think that everything is fixed, but when you then unleash the next part of the plot, they actually realize that there is more to it all.