3 Replies Latest reply on May 1, 2018 1:19 PM by Deepak Rai

How to divide a sum(if sales type = A then [sales]end) / sum(if sales type = B then [sales]end)?

Hi Tableau Community,

I have Sales Type as a dimension and there are two types - A & B. For each month, I would like to divide sales type A # sales divided by sales type B # sales. # Sales is my measure.

I have the function:

SUM(IF [SALES TYPE] = 'A' THEN [# SALES] END) / SUM(IF [SALES TYPE] = 'B' THEN [# SALES] END)

I have date as my columns and I put this calc pill into the rows. When I do that it says "AGG(SALES A/B)" and shows up as all nulls.

Is there any solution to this?

Thanks,

Ava

• 1. Re: How to divide a sum(if sales type = A then [sales]end) / sum(if sales type = B then [sales]end)?

Hi Ava,

I just solved a similar today. Have a look here.

Calculating a value using the same column...

Thanks

Deepak

• 2. Re: How to divide a sum(if sales type = A then [sales]end) / sum(if sales type = B then [sales]end)?

Because my data is then broken down monthly, is it possible to get this calc to work each month? with the Fixed calc it shows the same value every month. I need it to change over time.

• 3. Re: How to divide a sum(if sales type = A then [sales]end) / sum(if sales type = B then [sales]end)?

{Fixed DATETRUNC('month', [Date]): SUM(Same Thing from previous calculations)}