I'm creating a View to count the total number of unique values for a text field. This text field has a limit of one during input, so there are no additional values to check. I tried the aggregate and distinct options in the advanced tab, but I can't seem to get it to work properly.

I picked count distinct, but it still shows the duplicates as seen in the screenshot below.

enter image description here

2 Answers 2


Try to do the next thing:

Enable distinct option in query settings. Then in field's aggregation settings choose count DISTINCT option(not just count!).

Hope it'll help. This worked for me.


The drupal zealots will hate me for this for using php in the ui. I used php views and did a custom sql query to output the number of unique values for a field. My field was called campaign.

$campaign_query = db_query('select count(distinct(field_campaign_value)) from field_data_field_campaign');
$campaign_total = $camp_query->fetchAll();

$ctotal = $campaign_total[0]->{'count(distinct(field_campaign_value))'};

echo '<div class="views-php-totals">'. $ctotal .' Campaigns</div>';

The "proper" drupal way to do it is the create a new module and inject that code into the views header. But if your just a solo dev or a small team, doing my way would be the quickest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.