KNOWLEDGE BASE

How to display sales totals for the past N days


Published: 22 Jun 2022
Last Modified Date: 23 Jun 2022

Question

How to display sales totals for the past N days.
For example,
If N is 3 , the output results as follows.
User-added image

Environment

  • Tableau Desktop

Answer

By following the steps below,  Sales Totals will change dynamically depending on the value 'N' entered in the parameter.

User-added image

<STEP 1 >
-Preparation-
1. Connect to Sample Superstore.
2. While right-clicking drag [Order Date] to Rows > Select 'Order Date (Discrete)'.
3. Drag [Sales] to the cross tab.
User-added image

<STEP 2 >
-Calculate sales totals for the past N days-
4. Create a new parameter as following.
User-added image
5. Right click on [Enter past days] > Show parameter
6. Create a new calculated field as following.
     Name : Sales Total
     Calculation : WINDOW_SUM((SUM([Sales])),-[Enter past days],0)
7. Drag [Sales Total] to the cross tab.
User-added image
Did this article resolve the issue?