Tableau Prep: Difference From

"Difference From" is a multi-row calculation, available in the new Tableau Prep Builder version 2023.2.

A "Difference From" calculation computes the difference between the current value and a value N rows before or after the current row. This can be used to work out the difference from the previous period, a specific date, or a calculated value, for example. This feature is useful for visualizing and gaining a better understanding of the trends and changes in your data.

In this example, we're going to look at finding the difference from the previous month's sales. Start by inputting your data. Then, on the field containing the values from which you would like to find the difference, left-click on the ellipsis in the top right corner and select 'Create a Calculated Field,' then 'Difference From.'

A popup will occur, allowing you to select what you want to 'Group by,' 'Order by,' and 'Compute Using.'

'Group by' lets you specify how the calculation should be grouped or partitioned. To apply the calculation to all rows in the table, you can accept the default value 'Full table' for the group by.

'Compute using' Sales, as this is the value from which we want to work out the difference and should be the field where you selected the 'Create Calculated Field > Difference From' menu option.

'Order by' the selected field that you want to use as the sort order. In this case, it will be the Date field, as we want to calculate the difference from the previous month's sales.

'Difference From' also allows you to calculate the difference from the time frame ahead, and the number of time frames can be edited by clicking on the up button next to the '1.' This could allow us to calculate the difference in sales, for example, from 3 months before the current month. But for now, we will stick to just looking at the difference from 1 month before.

Then just click 'Done' in the top right corner of the 'Difference From' window.

You should now have a new calculated field named 'Calculation 1,' which will show you the difference in sales compared to the month before it. It is always good practice to rename fields, so double click on the title to suitably rename it. I've chosen 'Sales Difference From Prev Month' and dragged my column to the right.

My final output is:

The null will exist at the top (or the bottom if you chose the next value) as there is no previous month(s) for it to take a Sales value to find the difference from, so don't worry about that.

Author:
Beza Taye
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab