Display entries related to a category (only bottom level) I have a 2 level category system. Some have children, some do not.
How can I display entries related to the last level only?

If a category has no children, it should show the entries related to the 1st level. And if there are children, it should show entries related to that child category only.

The code below currently shows both levels, which I don't want. How can I tell Craft to look for the last (bottom) level only?

{% set entries = craft.entries.relatedTo(category).order('dateYear','comp_opus','title').limit(0) %}
{% for category in craft.categories.group('compositions').relatedTo(entries) %}
    {% for entry in entries.relatedTo(category).limit(7) %}
        {# Do stuff #}
    {% endfor %}
{% endfor %}
You can loop through your top level categories and check if descendants are available. Then collect the relevant category IDs that you can later use to filter the ElementCriteriaModel. 

{# Define array before loop #}
{% set bottomLevelCatIds = [] %}

{# Get top level categories only #}
{% set topLevelCats = craft.categories.group('compositions').level(1) %}

{# Loop through categories and collect relevant IDs #}
{% for topLevelCat in topLevelCats %}

    {# Check for child categories #}
    {% if craft.categories.descendantOf(topLevelCat).descendantDist('1')|length %}

        {# Merge child category IDs #}
        {% set 2ndLevelCatIds = craft.categories.descendantOf(topLevelCat).descendantDist('1').ids() %}
        {% set bottomLevelCatIds = bottomLevelCatIds|merge(2ndLevelCatIds) %}

    {% else %}

        {# Merge to level category ID #}
        {% set bottomLevelCatIds = bottomLevelCatIds|merge([topLevelCat.id]) %}

    {% endif %}

{% endfor %}

{# Get the bottom level category models #}
{% set categories = craft.categories.id(bottomLevelCatIds) %}