KNOWLEDGE BASE

How to create a stacked bar chart of new and existing customers, with customers who have not purchased in the last N months as new customers


Published: 05 Feb 2023
Last Modified Date: 06 Mar 2023

Question

How to create a stacked bar chart of new and existing customers, with customers who have not purchased in the last N months as new customers.

<IMAGE>
The number entered in the parameter is calculated as N.
User-added image

Environment

  • Tableau Desktop

Answer

1. Drag [Customer Name] to Rows.
2. With right clicking [Order Date] to Columns -> Select [MY(Order Date)].
3. Create a new parameter as following.
User-added image
4. Right click on [Select Months] -> Show Parameter
5. Create a new calculated field as following.
    Name : New Customer
    Calculation : IF SUM([Sales]) > 0 AND IFNULL(WINDOW_MIN(SUM([Sales]),-([Select Months]),-1),0) = 0
                         THEN 1
                         END
6. Create a new calculated field as following.
    Name : New Customer Window_SUM
    Calculation : WINDOW_SUM(New Customer)
7. Create a new calculated field as following.
    Name : Existing Customer
    Calculation : IF SUM([Sales]) > 0 AND WINDOW_MIN(SUM([Sales]),-([Select Months]),-1) > 0
                         THEN 1
                         END
8. Create a new calculated field as following.
    Name : Existing Customer Window_SUM
    Calculation : WINDOW_SUM([Existing Customer])
9. Drag [Measure Name] to Color on Marks.
User-added image
10. Right click on [Measure Name] on Color -> Filter -> Check in only [New Customer Window_SUM] and [Existing Customer Window_SUM].
User-added image
11. Drag [Measure Values] to Rows.
12. Change chart type to Bar from Automatic.
User-added image
13. Right click on [New Customer Window_SUM] on Measure Values Pane -> Edit Table Calculation -> Set as following.
User-added image
14. Right click on [Existing Customer Window_SUM] on Measure Values Pane -> Edit Table Calculation -> Set as following.
User-added image
15. Create a new calculated field as following.
      Name : First Filter
      Calculation : FIRST()=0
16. Drag [First Filter] to Filter Pane -> Click on "All" -> OK
17. Right Click on [First Filter] -> Edit Table Calculation -> Set as following.
User-added image
18. Right Click on [First Filter] -> Edit Filter -> Check in only "True".
User-added image
19. Right click on [Customer Name] on Rows -> Show Header.
Did this article resolve the issue?