7 Replies Latest reply on Oct 16, 2018 8:23 AM by Thomas Rones

# Calculated field challenge

This is my first post and I am coming from only couple of days of exposure to Tableau. So please excuse my basic questions...

My challenge is to sort my data into a desired newly created category.

I have three basic logical categories in my raw data,

1. series Ax... To identify this I created a set.

2. series ISxxxx... Category identified with "beginswith"  clause

3.series other...  All remaining Categories

Now a value might belong to either of these 3 categories or to all of them. However, "series Ax" relationship with corresponding value needs to take priority over all others Category-Value relationships, followed by series "ISxxxx-Value" set

Thus in our example

All records with  Value V1/V2 should be grouped together and may be say labelled as "Cat A" in Calculated field.

All records with  Value V3 should be grouped together and may be say labelled as "Cat B" in Calculated field.

All records with  Value V4 should be grouped together and may be say labelled as "Cat C" in Calculated field.

Raw Data

 Category Value A1 V1 A2 V2 IS001 V1 IS002 V2 IS003 V3 1234 V1 235 V2 3245 V3 23456 V4

Expected Data

 Category Value Calc Field A1 V1 Cat A A2 V2 Cat A IS001 V1 Cat A IS002 V2 Cat A IS003 V3 Cat B 1234 V1 Cat A 235 V2 Cat A 3245 V3 Cat B 23456 V4 Cat C

Message was edited by: Rakesh Dhankhar

• ###### 1. Re: Calculated field challenge

First welcome to the forum

please see the link Getting Started in the Forums  - it will present how to get the most out of you posts

since you did not provide a twbx workbook I can't be more specific but in concept you can just create a conditional If .. then ..elseif statement

and place you clauses sequential in order of your priorities

the statement will take the first True value and execute the then - and then will process the next record

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 2. Re: Calculated field challenge

Hello Rakesh,

Are you looking for this logic??

Calc Field=

CASE [Value]

when 'V1' then 'Cat A'

when 'V2' then 'Cat A'

when 'V3' then 'Cat B'

when 'V4' then 'Cat C'

END

• ###### 3. Re: Calculated field challenge

Rakesh,

There a a few easy ways to do this:

A) Create a group with the gui:

B) Create a calculated field:

CASE  [Value]

when "V1" then "Cat A"

when "V2" then "Cat A"

when "V3" then "Cat B"

when "V4" then "Cat C"

END

Both are included in the attached workbook.

• ###### 4. Re: Calculated field challenge

but I have a fairly exhaustive list of Values so writing a case statement for each value is not practical....

do we have a SQL IN clause or excel Vlookup() equivalent in Tableau...

• ###### 5. Re: Calculated field challenge

Thanks Jim...

I will try to upload the workbook for clarity...

also if else or case is not feasible as I have to read it from a list as the values run in 1000s...