14 Replies Latest reply on May 30, 2017 3:12 PM by vita nesvetailov

# Difference between two columns

I'm looking to calculate the difference between two columns in my data. In the attached sheet, I am trying to subtract column E and column C.

Search term is a dimension

Visits is a measure

% of total is a calculated field - the formula for this is:  SUM([Sessions]) / TOTAL(SUM([Sessions]))

Let me know if you need any additional information.

• ###### 1. Re: Difference between two columns

Are you having trouble writing the calculation or the result of the calculation?

sum([E column]-sum([C Column])

should work, obviously replacing with your actual column names

• ###### 2. Re: Difference between two columns

Chris, first you need to re-shape your worksheet to make it Tableau-friendly. (See attached). Also read this KB article. Then after you get rid of all the extra stuff, it's a straight forward calc just like Alex mentioned. (See attached)

--Shawn

• ###### 3. Re: Difference between two columns

Thanks for all the responses!

My data is shaped correctly.  The excel spreadsheet that I attached is an example of how my data looks in the view pane (as opposed to how it looks in my CSV file). In my view pane, I have "QUARTER(Date)" in my Columns field "Search Terms" in my Rows field and "Sessions" in my Text Field.

My difficulty comes in with subtracting one quarter from another for each search term.

Regards,

Chris

• ###### 4. Re: Difference between two columns

So in your actual view you have each QUARTER(Date) rather than "Day 1"  - is that correct? (I took Day 1 to mean Day 1 of Term 1 which I think is not your intention).

What result are you after? To me, after taking into account the decimal places/rounding, it looks to be calculating the result exactly how it has been told.

• ###### 5. Re: Difference between two columns

To make it easier, I attached a sample workbook of how it actually looks in my view. I am trying to subtract Q4 values from Q3 values for each search term. That's it

• ###### 6. Re: Difference between two columns

Can anyone help with this? I am still not able to answer my question.

• ###### 7. Re: Difference between two columns

Hi Chris,

One way to do this is to right click on SUM(Visits) on the text shelf and select Quick Table Calculation>Difference.

-Tracy

1 of 1 people found this helpful
• ###### 8. Re: Difference between two columns

This is a commonly requested issue.  I've attached a workbook with what I beleive is the solution you are seeking.  The trick was to first create the calculated field that provides the percentage of total per 'Search Term'.  Then, using the Year over Year table calculation, set that to change every quarter -- this is first built using the # of visits.  Before saving, however, be sure to swap out the Sum([Visits]) for the [% of Search Term] field created initially.  Edit the partitioning to be sure that one partitions of quarter, the other on Search Term.

Joe Mako developed a video showing the steps, which were then generalized to produce the attached workbook.
http://joemako.tumblr.com/post/3154354166/tableau-custom-table-calculation-tutorial

• ###### 9. Re: Difference between two columns

Perfect! Thank you so much, Brad!

• ###### 10. Re: Difference between two columns

Hi Brad - how do you get the one column to not display then (the % Diff Qt that has no data under it)  I have a dataset that I need to work as follows:

Dec14          YTD          Variance

A               20              32                12

B               15               21                6

What I get when I use your suggestion is more like:

Dec14      Variance      YTD     Variance

A               20                                32             12

B               15                                21              6

I need to remove the first Variance column...?

• ###### 11. Re: Difference between two columns

Jennifer! I have same issue. Can anybody advise me how to calculate difference between two columns? Thanks so much!

• ###### 12. Re: Difference between two columns

Hi,

there isn't excel linked to RandomNumber.twbx... and it is unusable.

• ###### 13. Re: Difference between two columns

Wow - I love how simple this solution is. Just what I was looking for. Thank you!

• ###### 14. Re: Difference between two columns

Hi Brad - I was trying to open the link you posted a while back about difference between two columns but it does not work. Do you by any change know where I can get the info? Trying to solve for this data and add another column. Thank you in advance! 