Bogdan
Bogdan

Reputation: 35

how to count occurrences of a value in Tableau?

I have a dataset with dog ids, dog names, and neighborhoods. I would like to display the n most popular dog names for each neighborhood. How can I do that?

I figured how to display counts for each name in each neighborhood, by simply dragging 'Neighborhood' and 'Animal Name' in 'Rows', and 'CNT(Animal Name)' in 'Columns'. But I don't know how to select the top 3 or 4 names for each neighborhood.

Upvotes: 3

Views: 5484

Answers (1)

Robert Crocker
Robert Crocker

Reputation: 678

I'm going to use Tableau's Sample Superstore dataset to walk through one way you can show the top N number of Products by Category. This example will easily transfer to Dog Names by Neighborhood.

I'll start by creating a Tableau calculation we'll use as a filter later.

RANK(COUNT([Product Name]))

enter image description here

I'll then put the Category and Product Names dimension on the Rows shelf and the Count of Product Names on the Text marks card.

We'll then place our Production Popularity table calculation on the filter shelf.

When the dialog box appears, just click OK.

Now we need to edit how our Table calculation runs to get the Top N Product Names within each Category.

enter image description here

Select Specific dimension and then uncheck Category or Neighborhood in your case.

enter image description here

Now we need to go edit our filter.

enter image description here

For this example, I'll set the upper limit to 3.

enter image description here

Click OK and you should see the top 3 Product Names by Category.

enter image description here

Of course, you'll want to adjust this example to fit your data.

Hope this was helpful. Happy vizzing!

Upvotes: 3

Related Questions