I am trying to analyze the initial purchase behavior of 2 subsets of users, mobile app users and non mobile app users.
I have client purchase history in a table where each row is a sale and contains whether the user is an app user or not and I've created a beast mode that uses variables "min sale date" and "max sale date" to filter the sales and determine the average spend per client.
First I calculate the total sales:
sum(CASE WHEN `Date` >= `Min. Sale Date` AND `Date` <= `Max. Sale Date` THEN
`Total`
END
END)
Then I calcuate the number of clients:
COUNT(DISTINCT (CASE WHEN created_at_clients
>= `Min. Sale Date` At
AND created_at_clients
<= `Max. Sale Date` THEN
unique_mb_on_sale
END))
Then I simply divide the first by the second to achieve the avg. spend per client for the given date range.
I want to be able to filter this equation so that it only includes the client's first purchase so I did the following:
CASE WHEN Date
>= Min. Sale Date
AND Date
<= Max. Sale Date
THEN
RANK() over (PARTITION BY unique_mb_on_sale
ORDER BY Date
)
END
However when I try to filter based on this rank value it does not work. Somehow everything has a rank of 1 when plotting the avg. sale per client on the y-axis and app user vs. non app user on the x-axis. Is there any way around this?