3 Replies Latest reply on May 18, 2016 9:17 PM by Rohan Malusare

# Creating a Calculated Field to Compare Revenue Between 2 Weeks

Hello,

I have revenue data for different products spanning two weeks.

My columns are: Product Name, Week and Revenue.

What I'm trying to do is create a calculated field that would give me a 1 if week 1's revenue is greater than week 2's for a given product, and a 2 if the reverse is true.

However, everything I try doesn't work, I thought using a parameter as a variable would work, but I get errors there as well.

Any tips you could provide would be greatly appreciated as I am just learning Tableau now.

• ###### 1. Re: Creating a Calculated Field to Compare Revenue Between 2 Weeks

Hi Kevin,

Please check the attached sample workbook.

Thanks and regards,

Rohan Malusare.

2 of 2 people found this helpful
• ###### 2. Re: Creating a Calculated Field to Compare Revenue Between 2 Weeks

Thanks, Rohan.

Using your workbook I was able to get essentially what I wanted.

Here's my calculated fields based on yours:

DIMENSIONS

Week 1:

DATETRUNC('week', {MIN([Week])})

Week 2

DATETRUNC('week', {Max([Week])})

MEASURES

Week 1 Rev:

IF DATETRUNC('week',[Week]) = [Week 1] THEN [RevPast7Days] END

Week 2 Rev:

IF DATETRUNC('week',[Week]) = [Week 2] THEN [RevPast7Days] END

Sales Variance:

(sum([Week 2 Rev]) - SUM([Week 1 Rev]))/SUM([Week 1 Rev])

Thanks!

• ###### 3. Re: Creating a Calculated Field to Compare Revenue Between 2 Weeks

Welcome Kevin Henely