3 Replies Latest reply on Dec 5, 2016 7:16 AM by Walt Reed

# Sum lines with condition

Hello,

I have to sum some columns to make a average calculation, but I have to do it with some conditions.
Example:

COLUMNS:

REGION      -     NAME          - Month            -      COST

...........

I have to make a chart with COST/MONTH

dividing the charts by region and name.

But I Have to make a double axis chart making a new column (Cost Average) That will be a calculated column

Something like.

The sum of the cost for the months I have divided by the number of lines.

BUT. again I have to divide this column by the categories Region/Name

So, the calculated filed would be something like

SUM(COST)/count(lines), but I have to sum the cost only for the NAMES and REGIONS that are equal.

name = ABC, Region = Region1

Is there anyway to make this calculation?

• ###### 1. Re: Sum lines with condition

Hello Guilherme Leitão,

Is it possible to provide a small amount of sample data in a Tableau .twbx file to share with the community and one example of the output expected?  I think what you want is pretty easy but seeing some data and an example of what you believe is the 'answer' will help us to help you.

Oh - and please let us know the version of Tableau that you are working in.

Thank you

Patrick

• ###### 2. Re: Sum lines with condition

Patrick,

Its a simple table

region number

A        12

B        9

C        5

A        11

B        23

A        9

C        2

I solve the problem in my OracleDatabase, at the SQL adding the lines sum, but not at the TABLEAU

Result         SUM_FLAG

A     32        Y

B     32        Y

C     7          Y

plus the above lines, by this I add one more column just to know if it was the sum

• ###### 3. Re: Sum lines with condition

Hi Guilherme,

I agree with Patrick, providing us with a sample packaged workbook or Excel file would help a great deal.

Walt