user2195252
user2195252

Reputation: 99

Tableau: filtering based on values of other variables of a parameter

I have a simple problem on Tableau I am not able to solve.

I would like to display a graph showing a measure over time. I would like to compare one client that the user select through a parameter to all other clients not selected. The graph would display two lines with 2 different colors: one for the selected client, the other line for others clients. The idea is to have a benchmark.

However I would like to filter the other clients with a condition like: if vertical(other clients)=vertical(selected client) then vertical(other clients), meaning that I would like only to keep the clients that have the same vertical than the selected client. This in order to avoid the user to filter manually by selecting the vertical of the selected client.

Is it possible to do that ? if yes, please let me know how!

Many thanks for your help!

Upvotes: 3

Views: 27166

Answers (1)

Inox
Inox

Reputation: 2275

I have no idea what a "vertical" means in this context, but the solution for the first part is pretty straight forward.

Create a calculated field called [Selected Client]. Assuming your client name is stored in [Client Name] and you created a parameter called [Client], this calculated field would be:

[Client Name] = [Client]

Then use it as a dimension (like drag it to rows).

You can also do

IF [Client Name]  = [Client]
THEN [Client Name]
ELSE 'Others'
END

This way is easier to understand who is the selected client.

Now the second part is more tricky. I suppose you want to filter only the clients that share an attribute with the selected client (your "vertical" thing). I'm not sure this is the best solution, but it is the one I came up with.

First let's change the [Selected Client] field a little bit:

IF [Client Name]  = [Client]
THEN '1- ' + [Client Name]
ELSE '2- Others'
END

This will help us sort on the next step. Now create a calculated field called [Filter vertical]:

LOOKUP(ATTR([Vertical]),FIRST()) = ATTR([Vertical])

Now this is important. Drag Vertical to rows (before [Selected client]. Now drag [Filter vertical] to Filters. Then Edit table calculation, Compute using Advanced. Put everything to the right (Adressing), Sort Field, Selected Client, Maximum, Ascending.

Now with our little twist, the selected client will always be the first on the list. And our filter will keep only the clients that has the same Vertical as the first of the list (which is our client).

It is important to have [Vertical] on the worksheet because table calculate partition and address only what is on the worksheet. If it is not there, it won't be considered.

Upvotes: 3

Related Questions