IF [Year] = 2012 THEN "2012" ELSE "Other" END
This statement returns the string "2012" if [Year] = 2012, and "Other" if [Year] <> 2012. (For those who are less techy, <> is the "not equal to" operator.) As usual, we will use the Superstore Sales sample data set in Tableau.
- Create a graph of Sales by Container
|Sales by Container|
- Categorize the Containers by how much Sales they generate
- Create the following calculated field
- Add [Container Category] to the graph to check the results
|Sales by Container (with Container Category)|
We've created a simple calculation that tells us how our Containers are performing, without having to scan through a list of numbers. We could make this even easier by adding colors, or using something other than a text table. However, we'll leave that up to you.
Let's shift over to that trick we mentioned earlier. Let's say you want to calculate the total sales for your containers like we did earlier. However, the Boxes should only be calculated for the last 30 days and everything else should be calculated for the last 45 days. We've often received the question "How do you calculate a total over the last X days for one product and Y days for another?" You're about to see!!!
- Create the graph of Sales by Category
- Filter the graph to only show the last 30 days
Wait a minute!!! If we filter the graph to only show the last 30 days, all of the containers will show the last 30 days; the same goes for 45 days. How do we make them different?
- Remove the Date filter (if you added it at all)
- Calculate the 30 day sum for boxes and 45 day sum for the other categories
- Create the following calculated fields
This is a complex step; so, we'll walk through it step-by-step. First, decide which type of container you have as follows:
|Container is Box?|
|Augmented Sales by Container|