8 Replies Latest reply on Feb 11, 2019 9:34 AM by Udi Sabach

# Calculating % Difference

Hi,

I tried various table calculations, but could not get this to work.

I am looking to compare same segment YoY. These segments are defined using a calculation field.

How do i write a calculation that looks at the same user segment year over year?

Thanks

Udi

• ###### 1. Re: Calculating % Difference

We'll probably need to see some data and/or a packaged workbook in order to assist. The structure of your data is really critical to answering this question.

• ###### 2. Re: Calculating % Difference

Hi Ken,

My data is complex as i am joining from various sources. Basically, we have a dedicated email campaign per segment. And therefore, each dedicated email has its own metrics. i am using the mailing name field to determine which segment a given mailing is for and group them as such---

IF CONTAINS(LOWER([Mailing Name1]), "exhibitors")

THEN "Exhibitors"

ELSEIF CONTAINS(LOWER([Mailing Name1]), "speakers")

OR CONTAINS(LOWER([Mailing Name1]), "past speakers")

THEN "Speakers"

ELSEIF CONTAINS(LOWER([Mailing Name1]), " pa")

OR CONTAINS(LOWER([Mailing Name1]), "_pa")

etc...

Similarly, looking at the mailing name field, i have a calculated field that groups mailing by year:

IF CONTAINS(LOWER([Mailing Name1]), "2017")

THEN "2017"

ELSEIF CONTAINS(LOWER([Mailing Name1]), "2018")

THEN "2018"

ELSEIF CONTAINS(LOWER([Mailing Name1]), "2019")

THEN "2019"

ELSE "Other"

END

Does this help?

• ###### 3. Re: Calculating % Difference

Hello Udi,

You could use Tableau's built in YoY table calculation. For this to work you must have a date field in the view. As I can see you are deriving years based on certain conditions. Try to convert it to the date data type. Once you do that you can easily calculate YoY.

Here is an example for your reference.

Hope this gives an idea.

~Tushar

• ###### 4. Re: Calculating % Difference

THank you Tushar! Once i used the date field instead of the calculated field, i was able to use the table calculation!

• ###### 5. Re: Calculating % Difference

I spoke too soon. I can not use the date field because i have mailings that are dated in 2018, yet i want to attribute them to 2019. Which is why i am using the mailing name (i look for 2019 or 2018 in the name) and grouped it that way.

IF CONTAINS(LOWER([Mailing Name1]), "2017")

THEN "2017"

ELSEIF CONTAINS(LOWER([Mailing Name1]), "2018")

THEN "2018"

ELSEIF CONTAINS(LOWER([Mailing Name1]), "2019")

THEN "2019"

• ###### 6. Re: Calculating % Difference

No need to convert, try this:

Set this as:

If this doesn't help, please share a dummy .twbx file.

~Tushar

• ###### 7. Re: Calculating % Difference

perfect! thank you!