I have a very similar question what I already had last weeks ago: Get all time unique values in BigQuery
I have a database like this:
ID | Day | Value |
---|---|---|
1 | 2021-09-01 | a |
2 | 2021-09-01 | b |
3 | 2021-09-01 | c |
4 | 2021-09-02 | d |
5 | 2021-09-02 | a |
6 | 2021-09-02 | a |
7 | 2021-09-02 | e |
8 | 2021-09-03 | c |
9 | 2021-09-03 | f |
10 | 2021-09-03 | a |
I'd like to count how many different rows I have daily and all time, but the all time uniqueness should count only with the date before (the business logic behind that I'd like to count if the user is new). The difference with the question before that I'd like to leave the rows but I'd like to see the uniqueness by rows (as a new column). It's almost the same what we have on Google Analytics as a new or returning user. So if a user get the site on 2021-09-02 and get to the site on 2021-09-03, first I'd like to see as New user but on 2021-09-03 I'd like to see a Returning user. so I'd like to see this output
ID | Day | Value | Type |
---|---|---|---|
1 | 2021-09-01 | a | New |
2 | 2021-09-01 | b | New |
3 | 2021-09-01 | c | New |
4 | 2021-09-02 | d | New |
5 | 2021-09-02 | a | Returning |
6 | 2021-09-02 | a | Returning |
7 | 2021-09-02 | e | Returning |
8 | 2021-09-03 | c | New |
9 | 2021-09-03 | f | New |
10 | 2021-09-03 | a | Returning |
I can do it if I only check it on one day but I can't do it if I check these on the whole database because of the date before checking.