Calculating Total Users in GA4 BigQuery

Do you want expert help in setting up/fixing GA4 and GTM?

If you are not sure whether your GA4 property is setup correctly or you want expert help migrating to GA4 then contact us. We can fix your website tracking issues.

Here is how you can calculate the total number of users in GA4 BigQuery.

GA4 defines ‘Total users’ as the total number of unique users who have logged an event.

The ‘Users’ metric is not available as the default field in the GA4 BigQuery export schema.

It needs to be calculated manually.

To calculate the total number of users, use ‘Common Table Expressions (CTEs)’ and count the unique values of the ‘user_pseudo_id’ event parameter:

‘user pseudo id event parameter

The ‘user_pseudo_id’ is an event parameter which is extracted as a string value. It is a unique identifier for a user. 

Let us suppose you want to query the data which meets the following requirements:

  1. You want to query data from a particular date range, say Jan 1 to Jan 31, 2024.
  2. You want to calculate the ‘Total users’ metric.

You can use the following SQL code:

WITH total_users_cte AS (

  SELECT

    COUNT(DISTINCT CAST(user_pseudo_id AS STRING)) AS total_users

  FROM

    `dbrt-ga4.analytics_207472454.events_*`

  WHERE

    _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’

)

SELECT

  total_users

FROM

  total_users_cte

Note: Make sure to use your own Table ID. Otherwise, the SQL won’t work.

Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button. 

You should now see the query result like the one below:

query results total users ga4 bigquery

That’s how you can calculate ‘total users’ in GA4 BigQuery.

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade