6 Replies Latest reply on Mar 31, 2016 9:43 PM by Mahfooj Khan

# Calculate difference between two columns composed of sum number of records.

I have a table that looks like this:

Category
TomBobDifference
Chairs1020
Table58
Door2015

All the numerical values are just sum number of records for each of the categories.

How can I calculate a third column (Difference) using Tableau?

Thanks

• ###### 1. Re: Calculate difference between two columns composed of sum number of records.

Has anybody tried this calculation?

• ###### 2. Re: Calculate difference between two columns composed of sum number of records.

Its very simple. Just create a calculated field called "Difference"

Then drag Category to row shelf and Tom, Bob and Difference on label.

You will get this output.

I hope this is what you wanted

Mahfooj

• ###### 3. Re: Calculate difference between two columns composed of sum number of records.

Hello Mahfooj,

Thank you for your response, however, that does not work necessarily.

I have attached a sample workbook, could you take a look again?

Thanks!

• ###### 4. Re: Calculate difference between two columns composed of sum number of records.

Do you mean to say the difference of records between item and furniture?

If yes then pls follow the difference calc field in the attached workbook. Else pls provide the expected output.

Mahfooj

• ###### 5. Re: Calculate difference between two columns composed of sum number of records.

This is exactly what I was looking for!

Can you walk me through the formula?

• ###### 6. Re: Calculate difference between two columns composed of sum number of records.

Sure! My pleasure!

See this is the calculated field which I've used to calculate the difference.

Here,

ZN() function replace null to zero, If found.

LOOKUP() function is the interesting part which doing your job

In the Difference table calculation, we want to compare a value against itself in a previous (or simply, a different) partition. Notice how the second value in the calculation is wrapped in a LOOKUP() function, which "looks" at the previous partition's value and then subtracts it from the next one, etc. The -1 declares which partition is in relation to the base of the calculation.

Mahfooj

3 of 3 people found this helpful