Tableau Tip: Count Distincts with Google BigQuery


Tableau Tip: Count Distincts with Google BigQuery

by Anthony Ball

Tableau does a great job of connecting to a variety of databases, but it sometimes needs help on the database end to get the results we need to make hot visualizations. One such example showed itself when connecting to Google BigQuery.

The issue? Count distincts. BigQuery doesn’t handle count distincts like one would expect. It gives a statistical approximation (inaccurate) result. Fortunately, there’s a way to fix this. You can pass the logic directly to BigQuery to force it to CountD.

Just follow these steps:

Step 1

In Tableau, create a new calculated field using the dimension you are wanting BigQuery to count distinct:

Tableau: Create Calculated Field 

Step 2

Create a SQL Pass Through calculation:

Tableau: SQL Pass Through calculation

Step 3

Create a calculation using the syntax in the image below. In this example, we are getting a count of unique employees based on the Employee ID field.

Use this syntax

Note: You may now use your newly created calculated field as you would any other; however, given that this is an aggregate measure, it may only be used with other aggregate measures. Also, be mindful that this solution hurts performance (see our Tableau Performance Checklist for best practices), so only use this when you must.

KeepWatch by InterWorks

Whether you need support for one platform or many, our technical experts have you covered.

More About the Author

Anthony Ball

Analytics Consultant
The Tableau Performance Checklist: Local Computations – Table Calculations Here’s the second item under Local Computations: “Table calculations are powerful, but they can be slow. They are dependent on ...
Tableau Conference 2015 Told in Selfies Tableau Conference 2015 officially ended a little over a week ago, and I’m already missing Vegas and all my fellow InterWorkers. ...

See more from this author →

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK


Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Geschäftsführer: Mel Stephenson

Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072


Love our blog? You should see our emails. Sign up for our newsletter!