4 Replies Latest reply on May 22, 2019 9:34 AM by Ken Flerlage

# How to Divide 2 calculated fields in Tableau

Hi,

There are 2 calculated fields and I need to do division on them...….Calc1 / Calc2 and this is giving me nulls. Unable to attach the workbook.

I am just replicating the same example in Super store.

1. Sub_cat_Chairs

If [Sub-Category] = 'chairs' THEN [Sales]

END

1. Sub_cat_Tables

If [Sub-Category] = 'Tables' THEN [Sales]

END

I need to do “Chairs by Tables” with below formula.

[Sub_cat_Chairs]/[Sub_cat_Tables]

When I pull this into rows I am getting null values,
although we have values for the corresponding calculated fields. Please check attached SS.

Can some one help me solve this issue so that I can apply
the same in my Project.

• ###### 1. Re: How to Divide 2 calculated fields in Tableau

You have a level of detail problem. These calculations will always operate at the row level. Since a row can only have one sub-category, then one of these will always be NULL. My guess is that you want to step outside of the level of detail to do a more global calculation across your entire data set. In that case, you'll need to use a level of detail calculation:

Sub_cat_Chairs

{FIXED : SUM(

If [Sub-Category] = 'chairs' THEN [Sales]

END

)}

Sub_cat_Tables

{FIXED : SUM(

If [Sub-Category] = 'Tables' THEN [Sales]

END

)}

That should then give you a result. For more, see FIXED Level of Detail Expressions - Tableau

Also, you'll want to be careful of the order of operations, especially if you're going to be using dimension filters, so also see Tableau's Order of Operations - Tableau

1 of 1 people found this helpful
• ###### 2. Re: How to Divide 2 calculated fields in Tableau

Type as below for Charts by Tables.

SUM([Sub_Cat_CHAIRS])/SUM([Sub_Cat_TABLES])

• ###### 3. Re: How to Divide 2 calculated fields in Tableau

Thanks a lot Ken Flerlage for your Prompt reply, this helped my requirement.

• ###### 4. Re: How to Divide 2 calculated fields in Tableau

Great!