3 Replies Latest reply on Aug 13, 2018 11:36 AM by Okechukwu Ossai

# Finding the sum with 3 conditions

I need to find a way to sum the total spent from each individual from a data set containing an id, total_spend, and date. I would like to have tableau return a single value without displaying the contents of the table. I want the sum of total_spend with three conditions applied.

1. Condition_1 = where date between [start date] and [end date]. where [start date] and [end date] are both parameters.

2. Condition_2 = only include people who spent more than [threshold]. Where [threshold] is a parameter.

3. Condition_3 = I only want to see the top [percent] of the population that meets the first two requirements. Where [percent] is a parameter.

I can get the calculation to work only if the id's and the total_spend is displayed but since I'm dealing with millions of data points I just need a single value.

Any help is appreciated.

• ###### 1. Re: Finding the sum with 3 conditions

Hi Erenis,

If the calculation works when IDs and Total Spend are displayed, then you may need to hide the Total Spend column and use a filter to remove the extra rows.

Depending on how your calculation is set up; either of this calculated fields will work.

FIRST() == 0

Alternatively, LAST() == 0

Add the calculated field to the filter shelf and set to True. Since this is a table calculation, you will tell Tableau how to perform the calculation (Partitioning/addressing).

Hope this helps.

Ossai

• ###### 2. Re: Finding the sum with 3 conditions

Thanks, I've tried something similar to this but the query time is above

20min. Is there another way to approach this without having an exhaustive

run time?

On Mon, Aug 13, 2018 at 2:34 AM Okechukwu Ossai <

• ###### 3. Re: Finding the sum with 3 conditions

The slow query time is probably due to the size of your data (several million rows) and the number/type of calculated fields in your workbook. My suggestion will be to move some of the calculations to your database if possible. You can also create different data sources with different levels of aggregation to answer specific questions instead of using a single large data source as one-stop shop for your analysis.