Search code examples
binarytableau-apibinary-logic

Tableau Desktop - Create customized filter based on multiple values


I am struggling to find a solution to create customized filter using Parameter. I have excel sheet with sample data as following.

*-----------------*
| Customer | Type |
*-----------------*
|  A       |   E1 |
|  A       |   E2 |
|  B       |   E1 |
|  B       |   E2 |
|  C       |   E1 |
|  D       |   E2 |
*-----------------*

I want to create a filter with three values as following

- E1 & E2
- E1
- E2

So when I select Type E1 & E2 then Customer A and B should be displayed. Same when I select Type E1 then Customer C should be displayed.

I have tried to get to the final result but no success so far. Any help would be appreciated.


Solution

  • I propose a slightly different approach, assuming that not too much factors/levels are present in type field.

    Create a calculated field Dummy1 with calculation as follows

    {
    Fixed [Customer]: SUM
    (IF [Type] = 'E1' then 1 else 10 END)
    }
    

    This field will act like a binary number with every place as either inclusion or inclusion of any particular value. Like..

    For value 1 - It will filter E1 only (second filter value in your example) For value -10 - It will filter E2 only (third filter value in your example) For value- 11 - It will filter E1 and E2 both (first filter value in your example). Therefore your steps may be-

    Create another calculated field dummy2 as below

    CASE [Dummy1]
    when 1 Then 'E1 but not E2'
    WHEN 10 then 'E2 but not E1'
    when 11 then 'E1 and E2'
    END
    

    You can now create filter through dummy2 as desired

    Screenshot

    One more thing, if you have more values in type field, allocate them values as 1, 10, 100, 1000, and so on so that you can distinguish the type which one to include and which one to include depending upon the binary places in their FIXED sum value.