3 Replies Latest reply on Feb 26, 2013 2:05 AM by Andreas Linden

# How do I calculate a ratio of two different domains within a field?

Hi,

I'm trying to graph the ratio between two domains within a field - for instance, I could have a table consisting of the fields 'date', 'product', and 'revenue'; the 'product' field data can either be 'Mac' or 'PC'. How would I go about setting up a calculated field to work out the ratio of these two product types?

Many thanks

Andy

• ###### 1. Re: How do I calculate a ratio of two different domains within a field?

(IF [Product]="Mac" THEN SUM([revenue]) END) / (IF [Product]="PC" THEN SUM([revenue]) END)

• ###### 2. Re: How do I calculate a ratio of two different domains within a field?

Hi Andreas,

Shawn is right, however, you might have difficulty in getting the measure to populate.

Therefore, separate the two clauses into 2 separate calculated fields:

Mac Revenue:

(IF [Product]="Mac" THEN ([revenue]) END)

PC Revenue:

(IF [Product]="PC" THEN ([revenue]) END)

Then, create a third calculation to find the ratio:

sum([Mac Revenue])/sum([PC Revenue])

Hope this helps!

-Tracy

• ###### 3. Re: How do I calculate a ratio of two different domains within a field?

Thanks Tracy, Shawn! I can't seem to make the final calculation work though - the ratios all end up as null! It appears that, for each product/month calculation, Tableau either calculates a PC revenue or a Mac revenue, and sets one of the two to null - which is fine when summing the revenues of one of the products, but makes it difficult to calculate a ratio using these calculated fields.