6 Replies Latest reply on Aug 17, 2016 12:53 AM by Ben Adam

# Conditional Formula

Hi,

I'm trying to create a calculated field that will do the following:

If(FieldA) = "x" Then Sum(FieldB) / Sum(FieldC)

Could easily do in excel but can't seem to figure out how to do in Teableau ... any suggestions?

Thanks,

Ben

• ###### 1. Re: Conditional Formula

Hi Ben,

You need to wrap the calculation in the aggregate.

I.e.

SUM(IF [FieldA] = "x" then [FieldB] / [FieldC]))

• ###### 2. Re: Conditional Formula

Thanks for that Tom ... problem figures the calculation is returning don't seem correct.

Just in case I haven't explained this clearly ... for every value that equals "x" in [FieldA], I want the formula to sum [FieldB] and divide it by the sum of [FieldC]

Is that what the above should do?

Thanks

Ben

• ###### 3. Re: Conditional Formula

I can't really say with any certainty without seeing some sample data. Perhaps a level of detail calculation like {Fixed [Field A]: SUM([FieldB])/SUM([FieldC])} would work better as it would force the aggregation.

Please upload a Tableau Packaged Workbook including sample data.

• ###### 4. Re: Conditional Formula

You could try IF ATTR([Field A]) = "x" THEN SUM([Field B])/SUM([Field C]) END

• ###### 5. Re: Conditional Formula

This should work: SUM(IF [FieldA] = 'x' THEN [FieldB] END)/SUM(IF [FieldA] = 'x' THEN [FieldC] END)

• ###### 6. Re: Conditional Formula

Andrew, that seems to work. Cheers!