1. Window functions in Tableau
Welcome back. In this chapter, we'll be covering what window functions are in Tableau, why the size of your window function matters, as well as the concept of correlation with respect to time series!
2. What is a window?
Windows refer to specific partitions in your data you wish to analyze.
They're used specifically as an argument for window functions.
A windows size is determined based off 2 factors, a starting window and ending window.
Now provided neither a start or end is supplied, the window will be composed of the entire range of values.
3. What is a window function?
Window functions are known as moving calculations as they help smooth data over specific time windows.
Examples of this include window sums, moving averages, and moving standard deviations.
They're composed specifically of a measure, a starting window, and ending window.
However, it's important to note that window sizes are dynamic in nature.
4. How does window sizing work?
The number of data points in your window depends on the granularity you've selected.
Once the window size is established, this is then computed for each row using the window size and respective granularity.
In our examples below, we have a window size of 2, at a daily granularity.
The first window is composed of the first two entries, the third and fourth of January.
The second window is then composed of the second and third entries, the fourth and fifth of January.
5. How does granularity impact window sizing?
Previously we mentioned your results are dependent on the granularity chosen.
Let's illustrate this further.
On the left, we have our our window function that takes 2 values, the preceding value and the current row value at a daily granularity.
On the right, we have the same window function, but with our granularity weekly, the results have changed substantially.
The aggregation for each week is computed first, before the window calculation then aggregates the results.
This is a tricky concept so feel free to pause the video and scrutinize the tables if you wish.
6. What's the purpose of a window function?
Now as to why you'd want to use window functions - this is due to the temporary views windows provide.
Normal aggregation functions use the whole range of values - that's all they can do. Windows on the other hand are specific to the time window of interest and can be forward looking or backward looking.
Commonly used window functions include, window sum, window average, window standard dev, window correlation, and window median.
7. What's correlation?
Before we dive deeper into window functions, we need to take a step back and consider a concept known as correlation.
Correlation is the extent to which two variables share a linear relationship.
This is measured via the correlation coefficient which indicates the strength and direction of the linear relationship with values ranging from minus one to positive one.
A positive direction implies when one variable increases, the other also increases.
Inversely, a negative direction means when one variable increases, the other decreases.
8. How do window correlations work?
Now that we've covered our correlation definitions - we can dive back into window functions!
Window correlations measures the relationship between two signals over a specific time window to identify whether or not a relationship may exist.
In our example here, we can clearly see one correlation value being returned for furniture, office supplies, and technology.
Our window correlation here is comparing the sales and quantities for all products, irrespective of category.
This is in contrast to a singular correlation, which computes the pairwise correlation on a row by row basis.
9. Introducing the dataset
Now in this chapter, we'll be analyzing water trading activity and the seasonal transactions that take place.
Specifically, we'll be covering moving averages and window correlations.
10. Let's practice!
Now that we've covered the fundamentals of window functions and covered our dataset of interest; let's test your memory on what you've retained!