Counting active orders is equivalent to taking stock. An order is active before it is shipped. So an order is like part of the inventory before it leaves the warehouse.
In the previous post, we presented 2 approaches to solve the problem. Here we will show yet another solution: use the native PIVOT menu in the data source editor to solve the problem (Tableau 9+ only). The advantage of the new method is there is no need of custom SQL or scaffolding anymore.
The data source is the Superstore data in Excel. There are multiple versions of it. We use the same version as in the last post.
The main steps are:
1.Load the Excel data into Tableau. Select both Order Date and Ship Date columns. Click the drop down menu at the upper right corner and select Pivot.
2.We get two new columns: Pivot field names and Pivot field values.
Note that after the pivot, each original row is turned into two rows: one row for Order Date and another for Ship Date.
3. Rename the Pivot field names to be Date Type, and Pivot field values to be Date. This is for better readability.
4.Create a calculated field Value. This assigns value 1 to Order Date and -1 to Ship Date.
The logic here is, starting from an Order Date, we have an active order. On a Ship Date, we removed an active order.
5. Drag Value to the Row shelves and right click Sum(Value) to select Quick table calculation>Running total. The logic here is, an order will remain active until it is shipped. The running total will give us the daily count.
It is done! We can change Date to be Month or Week to see the number of active orders per Month or per Week.

Click the image to view or download the workbook.
The Pivot feature in Tableau 9 allows us to reshape data easily, without writing Custom SQL or scaffolding.
Nice one
ReplyDeleteThis help me! Thank you very much!
ReplyDeleteGlad to hear it helped!
Delete