top of page
Search

How to Compute The Difference Between Two Years Sales in Tableau Using Table Calculations & Aggregat



How do you calculate the difference between two years in tableau in this example I have sales in 2020 and 2021. And you can see the difference is 124 000. Let’s take a look at how to do this in tableau. I’ve brought year of order date and some of sales into the view I filtered it down to only 2020 and 2021. A copy of the sales Pill by holding control down and dragging it to detail I can change this to a quick table calculation and choose difference in order to bring it into the view let’s drag it on top of the numbers that gives me measure names and measure values this is the difference pill and drag it to the bottom and I can remove my pill off detail anything with a triangle is a table calculation so let’s open that by editing the table calculation and see that it’s being done a long year of order date if there are more dimensions in this view you would have to uncheck and check certain boxes let’s also see how to format this a little bit better we have two different columns with only one having a difference let’s write a calculation. And test if year equals 2020 then sales. And call this 2020 sales. Click apply okay let’s drag that on to measure names and let’s duplicate that pill and do the same thing for 2021. Apply okay let’s change this to 2021. And drag it to The View. That’s right one more calculation fourth difference. And let’s drag my sales difference into the calculated field you can see that the table calculation is simply sum of sales minus lookup sum of sales minus one so the previous value click apply okay and let’s put difference into measure values now I can remove Year from detail and remove sales remove the other sales let’s make sure difference is calculated right still by adding in table calculation and making sure it’s a long year. So now you can see 2020 sales of 609 2020 of 6733 and a difference of 124. One more thing you can do is change the calculation to be a little bit more simple to create a calculated field and just call it difference two and let’s test sum of 2021. Minus sum of 2020. That’s going to give us a difference as well just in a different way let’s bring that down in that case you don’t need year to be in the view so let’s completely remove that and remove the first difference and you can see the same difference value and that’s two ways to compute the difference of two years in Tableau hope this helps.

17 views0 comments
bottom of page