Can you find how many quarters it took for a customer to order again?

It was Lorna’s turn to set the challenge this week, and she opted for a gentle workout to soothe us into the Christmas holidays – I certainly appreciated it as I am super busy and super stressed trying to finalise Christmas presents and preparations!

I built this with 4 calculations in total. Let’s start by just building out a tabular view of the data, so we know what we’re looking for.

Add Customer ID and Order Date set to be a discrete (blue) exact date onto Rows.

To start with, we want to capture, against each customer, the earliest order date

First Purchase Date

{FIXED [Customer ID]: MIN([Order Date])}

Add this into Rows as a discrete exact date.

You can see that for every row associated to the same customer, the First Purchase Date matches the first row.

Now I want to identify the row that represents the first order for each customer

Order is first order

[Order Date] = [First Purchase Date]

Add this onto Rows and we can see the first row against each customer is True, while the rest are False.

I can now use this to identify the date of the 2nd order for each customer – it is the earliest date where the order isn’t the first order

Second Purchase Date

{FIXED [Customer ID]: MIN(IF NOT [Order is first order] THEN [Order Date] END)}

Add this onto Rows as a discrete exact date, and you can see that every row associated to the customer, now has the date that matches the 2nd Order Date listed.

Remove Order Date and Order is first order from the Rows and we have 1 row per customer with the 2 dates we’re interested in.

From this we can work out

Quarters Since First Purchase

DATEDIFF(‘quarter’, [First Purchase Date], [Second Purchase Date])

Add this onto Text, so you can validate the result.

Now we can build out the matrix.

On a new sheet add First Purchase Date to Rows and set to be at the discrete (blue) quarter level. Then add Quarters Since First Purchase to Columns and change to be a discrete Dimension.

This already gives us the shape we’re after. Right click on the Null value in the column heading and select Edit Alias and update the word to Lapsed.

Add Customer ID to the Colour shelf, and the click on the pill and change to be a Measure of Count Distinct. This will change how the viz is displayed. Adjust the colours accordingly.

Finally update the Tooltip to match the required text, and adjust the formatting so there are pale grey thin dotted row and column dividers on the pane only, but not the header.

Add the viz to a dashboard, and you’re done! My published viz is here.

Happy vizzin’!

Donna

2 thoughts on “Can you find how many quarters it took for a customer to order again?

  1. Thank you very much for your detailed response, Donna! I’m excited to connect with you on LinkedIn as well.

    I have a minor query regarding the comprehension of the question. The prompt asks, “Can you determine how many quarters it took for a customer to order again?” Shouldn’t this imply how many quarters, approximately 90 days each, have passed since the customer’s first order? However, the solution seems to interpret it as the actual quarters of the year. For instance, considering Customer ID BD-11770 with First Purchase Date 10/03/2021 and Second Order Date 2/05/2021, the solution calculates “Quarters since first purchase” as 1. In my understanding, since the first purchase occurred less than 2 months ago, i.e., fewer than 90 days, the customer hasn’t yet completed a full quarter to place the second order. But according to the provided solution, one quarter has passed since the end of March.

    I’m eager to hear your perspective on this.

    Like

    • Hi Parul
      This is a solution guide to a challenge provided by someone else, which in turn is just an example to demonstrate techniques and different concepts in Tableau. I have written my solution guide to match the challenge presented. If this was a real business dashboard, then yes, I concur that measuring the difference in quarters this way probably isn’t really sensible, and a more explicit definition should be provided. Feel free to provide a solution to the challenge that handles this if you wish.
      Regards

      Like

Leave a comment