2 Replies Latest reply on Dec 22, 2018 8:41 AM by Paul Wachtler

# Percent Difference of Two Fields

Hi!

I've been cramping my brain trying to figure out how to find the percent difference of two fields across a table.

If I have a Series A and Series B, is there a way I can (Series A - Series B)/ Series B across the table? These series are both independent measures.

I understand doing a percent difference on a running measure like the sum(Sales) for 2018 vs sum(Sales) for 2019, but how to for two different measures!

• ###### 1. Re: Percent Difference of Two Fields

Antonio,

Not sure what you are aiming for. I assume Series A and B are "measures". Is there at least one "Dimension" in your dataset for which both measures Series A & B are available in the dataset? Or please share your workbook in .tbwx format.

Regards,

Norbert

• ###### 2. Re: Percent Difference of Two Fields

Hi Antonio,

It sounds like you can accomplish this with a simple calculated field.  As Series A and Series B are individual measures, this means there is one value for each of these measures for each row in your data (or possibly a null or zero value).

The only thing to be mindful of is that Tableau will return an error if the denominator is zero or null, so we have to code for those conditions.  Create a field called [Percent Difference] or whatever else you'd like to call it.

IF [Series B] = 0 OR ISNULL([Series B]) THEN 0

ELSE ([Series A] - [Series B]) / [Series B]

END

Then you can have Series A, Series B, and your Percent Difference fields on your measure values shelf, measure names on columns, and then Percent Difference will calculate across your table.

Best,

Paul