6 Replies Latest reply on Dec 6, 2013 6:23 AM by Eric McDonald

# Filter Logic Required

I have what looks like a simple example but can't work out how to create the filter I want.

I have uploaded a packaged workbook with a sample data-set to illustrate the problem. The data looks like this:

 Stock Fund Index Microsoft 0 20 Oracle 20 25 Tableau 30 15 Google 0 15 eBay 50 25

I want to provide users with a filter / parameter which has the following exclusive choices (i.e. radio buttons):

Show Fund Only Stocks

Show All Stocks

I can't find an easy way to do this. You can create a calculated filed Fund != 0 which when True shows Oracle, Tableau, and eBay and when False (correctly) shows nothing. However the logic I want is to show Oracle, Tableau, and eBay when Show Fund Only Stocks is selected and all stocks when Show All Stocks is selected.

• ###### 1. Re: Filter Logic Required

Hi Eric,

Please find the attached solution. Please let us know if it is not working for you.

-Indumon

• ###### 2. Re: Filter Logic Required

Hi Eric,

Create a calculated field: -

if [Fund Only Choice] == 'Show All Stocks' then [Stock]

else if [Fund Only Choice] == 'Show Fund Only Stocks' then

if [Fund] != 0 then [Stock] end end end

Replace Stock from column with this field. Also put this field in filter section & exclude "Null".

This will work for you. I am using Tableau 8.1 & attaching a file here.

Warm Regards,

Prashant Sharma - India | LinkedIn

1 of 1 people found this helpful
• ###### 3. Re: Filter Logic Required

I managed to get this working myself as well. It uses slightly different logic to above answers.

(1) You can use a boolean parameter and IIF style logic in a filter.

[FUND] = IIF([Fund Only Choice],0,[FUND]+1)

(2) or make the parameter a float with values 0 for Fund Only and 999 for All:

[FUND] != [Fund Only Choice]

You have to assume in both cases you know your data-set will never have 999

Boolean logic is usually faster in Tableau than IF statement, although I'm actually not sure which one of the 4 works best!

• ###### 4. Re: Filter Logic Required

Thanks for sharing your solution too!

• ###### 5. Re: Filter Logic Required

Actually I think this is the best solution:

Step (1): Create a Boolean parameter named Fund Only Choice where True is aliased to Show Fund Only Stocks and False is aliased to Show All Stocks.

Step (2): Create a new calculated field named Fund Only Calculation:

IIF([Fund Only Choice],[Fund],0) != IIF([Fund Only Choice],0,1)

Step (3): Add Fund Only Calculation to the filter shelf and set to True

This method tries to use Boolean logic where possible to make it fast and avoids the problem of hard coding 999.

• ###### 6. Re: Filter Logic Required

And there's a further simplification:

Fund Only Calculation is even simpler if written:

NOT [Fund Only Choice] OR [Fund] != 0