Q:

Count all unique values

We are building a family community website with more than 600 members all over the world.
In craft.users we have added many fields and one of them is country.
We want to display and count all countries.
Example of the desired output could be something like:
Our members are living in the next 5 countries

the Netherlands (545)
Chili (26)
USA (14)
Italy (6)
Sweden (8)

A:

Something like this should do the trick:
{% set usersGroupedByCountry = craft.users.limit(null)|group('postaddress.country') %}

<ul>
    {% for country, users in usersGroupedByCountry %}
        {% if country and users|length %}
           <li>{{ country }} ({{ users|length }})</li>
        {% endif %}   
    {% endfor %}
</ul>

Note that if you want to order the list of countries, you'll need the SuperSort plugin. Here's how you would sort the list alphabetically:
{% set usersGroupedByCountry = craft.users.limit(null)|group('postaddress.country)|supersort('ksort') %}

Also note that if you have a lot of users (say, hundreds), it is probably a good idea to wrap the whole thing (including the {% set usersGroupedByCountry ... %} part) in a {% cache %} tag pair, for performance reasons.

