MIP Logo

Window Functions for Comparison

This post was originally published on The Data School blog between 2018 and July 2025, before our program was renamed to MIP’s Analytics Career Accelerator. References throughout this article to “The Data School” or “DS” all refer to what is now MIP’s Analytics Career Accelerator. The program, its people, and its commitment to launching outstanding analytics careers remain the same – just under a new name.

If you are having trouble viewing this article, please report it here. 

Window functions are among the most useful inbuilt functions in Tableau. These functions can be used while carrying out aggregation over a certain set of rows of our interest. These set of rows can be called windows. This puts the term ‘Window’ in window functions. They can also be used for carrying out comparative analyses.

The syntax is as follows:
window_function(AGGREGATION(['Measure_Name']),[offset])

If no offset is provided, the window function is applied for the whole table.

In the below example, months with the highest and lowest Profits are highlighted. This gives visual cue to the audience on high and low performing months by setting them apart.

How was this achieved?

This can be achieved by using the window function as follows.
This calculated field checks for the highest and lowest sum of Profit in the provided window. In this case, the entire table is considered.
Upon dragging the calculated field to the ‘Color’ mark, the values are highlighted.

 

Upon adding the ‘Year’ field, the granularity on the view is changed. However, the highest and lowest Profit values are highlighted considering all months for all 4 years in the view.

The highlighted Profit values can be changed to show highest and lowest values for each of the years in the view. This can be done by Right Clicking on the calculated field,
click on ‘Compute using’ and click on ‘Pane (down)’. Now each of the years in the view is considered as a window. This highlights the highest and lowest Profit values for each year.

So there you have it. A simple way of using window functions for comparative analyses.

Share this post