Skip to content
Advertisement

Determining Where Date Ranks | BigQuery

I have purchase data that I’m trying to analyze. I’m attempting to find the 2nd and 3rd purchases (and potentially 4, 5, etc.) for each user.

The data I have currently looks like this:

The first order column is looking at what was in the first basket that the customer purchased. Is there a way I can create another column that will tell me exactly what purchase number each line item is? Ideally, the table will look like this:

Basically, I want to look at each email and determine where the processed_date falls in respect to all other processed_dates that are registered to that user. The problem I’m trying to work around is when there are multiple line items for a particular processed_date.

Advertisement

Answer

Below is for BigQuery Standard SQL and assumes the processed_date column is of date type

If processed_date is a string – you can use below then

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement