2 Replies Latest reply on Aug 21, 2017 6:42 AM by Niranjan Patil

How to use filter values in calculated field for dynamic calculation ?

Hello All,

I am very new to Tableau. I have been trying to do calculation using selected values from filter but there is no way to get those values in Tableau.

Here is my calculated field where i am taking an average.

A_count + B_Count + C_Count + D_Count + E_Count + F_Count / 6   ( values of A_count ,B_Count ,C_Count ,D_Count ,E_Count ,F_Count  are coming from other calculated fields)

My filter is on values i.e. A, B, C, D, E, F (Filter type is multiple value(list) )

My requirement is :

when I select any of these values my calculation should change accordingly like below

say I selected A, D and E then my calculation will be

A_Count + D_Count + E_Count  / 3.    (selected values divided my number of selected values i.e. average)

I am looking for logic like below

If  select values = 'A' and select values = 'D' and select values = 'E'  then

A_Count + D_Count + E_Count  / number of selected values end.

I have tried using ATTR() and countd() function in Calculated field but it only works for single selection.

countd() funtion gives me count of selected filter values but i am not able to get actual values tso i could't able to perform above calculation.

• 1. Re: How to use filter values in calculated field for dynamic calculation ?

For your average calculation, the filtered out data is automatically excluded from the calculations, and you do not have to do anything special here.

1. In the below image, I have selected all the states, and showing you the average profit and sum of profit here.

2. Now, I am deselecting some of the states, and you can see that both the average profit and sum of profit values change.

• 2. Re: How to use filter values in calculated field for dynamic calculation ?

Hello Hari,

Thanks for answer. Actually all my fields are separate calculated fields.

Anyways I have changed my way of calculation and brought it in single calculated field and I used your solution to get my result.

Thanks again.