
A complete SQL guide for marketers and machine learning engineers. MAU, DAU and WAU. Firebase and Bigquery example. Nifty report template included. Read how to copy it in the end of this article. It’s free!
Counting Active users in your App might be tricky. What would you do? Count – active deviceIds or active accounts?
In order to effectively calculate your Active User numbers you will need a combination of both deviceId and userId.
Depending on your users you might face different scenarios where users may be using multiple devices, may have different accounts on one device and cross using each others devices and accounts.
What is this tutorial about?
This article is about how to calculate REAL Monthly/Daily/Weekly active user metrics using SQL.
You can apply different methodologies to calculate Active user numbers. This article aims to answer these simple questions:
- What is an "Active user"?
- How do we count users with multiple devices?
- How do we count users with multiple accounts on one device?
- How do we count users who cross use each other devices?
- How to visualize the results and create dashboards?
- How to identify real users? (helps to mark spammers for example)
I’ve created this handy Data Studio template. Feel free to use it.
Who is this article for?
- Marketers who might want to see the real picture.
- Analysts who have been asked to build user activity reports and charts.
- AI and ML experts who will probably want to use MAU/DAU/WAU flag as a categorical feature in their models.
What is an "Active user"
Let’s assume every client Application will log in several times a day when running. Each logon event can be recorded to your Data lake/Data warehouse along with the user id and the device id.
I wrote about Daily Active Users before in this article:
This is pretty much how Firebase logs users. You will have user_pseudo_id by default and user_id can be enabled like so:
Active users are often reported as Monthly active users (MAU), Weekly (WAU), and Daily (DAU). Let’s illustrate active users a little bit more with a visual example:

In the illustration above, you can see user logons each day after registration. Each coloured circle implies a user being active that day. User 'J'
was way active during each week 1–6. However, it still counts as 1 MAU (Monthly active user). So we can see 2 Active Users for that month, because all of the users were active at least once during that month.
If a user visits your app every day of the month, that’s a single user. Not 30 different users.
Let’s take a look at this sample dataset and run it in BigQuery:
You probably noticed that user id ‘E01’ has 2 devices (user_pseudo_id 2001 and 2000) in the dataset below.
We calculated users and that’s why it is 2 (not 3) MAU.
So MAU/DAU number totally depends on methodology you apply to your data.
If a user opened your App and then uninstalled it – is it a daily active user? For many dashboards – Yes, it is because they count deviceIds as users.
How do we calculate Monthly/Daily/Weekly active users?
No measure of DAU will be perfect. Real-world issues such as jail-broken devices mean that there will always be some uncertainty in any calculation.
From the four different scenarios in the diagram below, we can calculate DAU with confidence for the first three. The fourth scenario where an individual has several accounts but only uses them exclusively on different devices, would be impossible to detect. The calculation relies on using multiple accounts on a single device.

DAU Calculation
Method 1. Count unique devices
_…where multiple deviceids exist for a user, replace with just ONE.
Example:
Let’s imagine we have two users John and Emma. John has an Iphone and Emma is on Android and has two devices:
So here we can see 3 devices and 3 user accounts = 2 real users. Simple.
How to calculate DAU:
Run the SQL below and you will get 2 DAU.
For me personally this method is not the best one and I will explain why.
First of all, this is not reliable:
select user_id ,min(user_pseudo_id) as device_id
from ua
group by 1
;
Indeed, doing MIN on device_id
STRING might be wrong. In fact, in some cases it might be right because of this little thing below.
Let’s imagine the situation.
Emma has a second user account, she was using it on her tablet which is her second device, encountered an Application error and decided to re-install the App. For DAU calculation we assume this all happened within the same day. Her device_id on the tablet will be different as it’s a new one. We never know what new device_id would look like and MIN function would be working with a black box here. Run the SQL below and you’LL understand why.
DAU will be 3 when in reality it is 2(!):
I am actually OK with 3. The higher the better. However, according to business logic it must be 2.
Method 2.
…calculate linked accounts across all user devices.
This is a tricky method and I have to admit I spent some time trying to come up with the best solution for linking accounts across all active users with SQL.
In this scenario we will see even more complex example. Remember the illustration with different scenarios?

Let’s see how data would look like for each of them.
- Sceanrio 0. The most simple one. UserId
J
has only 1 device and was active on 2020–10–10:
('1000' as user_pseudo_id, 'J' as user_id, date '2020–10–10' as dt),
- Scenario 1. Where multiple accounts exist for 1 device we assume it is just ONE user. For example, User with device_id ‘2000’ has two accounts. Let’s call it user ‘E’:
('2000','E01',date '2020–10–10'),
('2000','E02',date '2020–10–10'),
- Scenario 2. Where multiple device_ids exist for ONE account we’ll count just ONE. For example, User ‘P01’ has two devices:
('3000','P01',date '2020–10–10'),
('3001','P01',date '2020–10–10'),
- Scenario 3. Now let’s look at this one below. User ‘D’ has 3 accounts across 2 devices. So we have TWO accounts on device_id ‘4000’ and TWO accounts on device ‘4001’. The problem is that we can’t apply the scenario 1 (Where multiple accounts exist for 1 device we assume it is just ONE user). Indeed, if we use this logic we will get 2 DAU (devices ‘4000’ and ‘4001’)
- when in real life it could be just ONE user. For example:
('4000','D01',date '2020–10–10'),
('4000','D02',date '2020–10–10'), - 4000, 4001 | D01, D02
('4001','D02',date '2020–10–10'), - 4000, 4001 | D02, D03
('4001','D03',date '2020–10–10')
Using D02 we can link accounts D01 and D03.
It also could be 3. For example, a family sharing a PC or a tablet. We don’t really know so let’s just call these accounts ‘linked’ and mark them as ONE using device and account footprints. So how do we do it with SQL? In this case we need to check if there is another DEVICE with same account using it.
Run this SQL in BigQuery:

Using this dataset you can produce a report displaying linked users. For example:

Conclusion
In this tutorial we have built a beautiful dashboard to show Daily Active user numbers and Linked accounts following the simple example and different user scenarios. Indeed, in many cases numbers simply don’t reflect the real picture. For example, re-installing the App or any drop-off device action will result in new device_id
identifier which may or may not end up increasing the total DAU number. As well as any jail-break device or user spam activity may significantly increase your DAU and make it inaccurate.
This hands-on project demonstrates how to use SQL (BigQuery standard SQL) and Google Data Studio in order to link users with multiple accounts and multiple devices and create a custom built analytics tool which can be easily adjusted to any business logic or methodology. This is a simple BI solution to understand the user base better.
Thanks for reading!
How to use this template
- Click this link and click Use template

Copy the Template. Image by author
- Click Copy report with datasets:

- Some widgets will appear broken but click one and then click Edit

- Select your billing project and click Reconnect:

Success!

Recommended read:
Key App Metrics with BigQuery Part 1: DAU/MAU
Expressions, functions, and operators in Standard SQL | BigQuery
https://help.amplitude.com/hc/en-us/articles/115003135607-Tracking-Unique-Users