2 Replies Latest reply on Aug 26, 2013 11:02 AM by Joshua Milligan

# Very easy question, I'm sure...  Within my data I have one field (Date) which has two values, (2012, 2013).  How do I create a calculated field that compares values between the same field name?

Assistance appreciated.

• ###### 1. Re: Very easy question, I'm sure...  Within my data I have one field (Date) which has two values, (2012, 2013).  How do I create a calculated field that compares values between the same field name?

Hi Ryan and welcome!

I'm sorry, but I am not sure what you mean.  You should be able to just pull the date field into the view, and see any corresponding values from the two years.  What kind of calculated field are you looking to create?  Can you post some more details about what you are trying to do here?  If you haven't already, you may want to review this helpful document:

http://community.tableau.com/docs/DOC-5065

• ###### 2. Re: Very easy question, I'm sure...  Within my data I have one field (Date) which has two values, (2012, 2013).  How do I create a calculated field that compares values between the same field name?

Ryan,

Welcome to the forums!  Please take a look at the link Matthew provided.

I'll take a stab at answering your question because I think I know what you are asking.

Tableau has 3 types of calculations:

1. Row level -- done for each row of underlying data.

2. Aggregate -- done at an aggregate level (such as SUM, MIN, MAX, AVG -- i.e. the sum of sales for each year).

3. Table calculation -- done after the initial query returns a table of aggregated data based on the fields used in the view.

Type 1 won't work because at a row level, the value for Year can't be 2012 and 2013.

Type 2 probably won't work because, although it will allow you to aggregate for each year, it doesn't give much flexibility to compare the slices of data.  (You could mix type 1 and type 2 to get a single result, but it still wouldn't be very flexible.)

Type 3, table calculations, are the most complex.  In this case, it is probably the way to go.  You might do some searching in the knowledge base for details on table calculations and specifically the LOOKUP function.

For example, create a field with the code

SUM(Value) - LOOKUP(Sum(Value), -1)

(where Value is the measure field you want).  In a view place whatever dimension(s) you want on Rows, and Year on columns.  Then place the new calculated field on Text.  By default it is calculated Table Accross which means that you are seeing the difference of the Sum of the Value for the current column and the Sum of the Value from the previous column (NULL if there is no previous column).

Regards,

Joshua