13 Replies Latest reply on Jan 14, 2014 11:23 AM by Jason Back

# How to write a dimension calculated field with a list of string values

Hello,

I am trying to create a calculated field with a list of string values.

I can create one string value by writing "Word that I want" in a new calculated field. But how would I write one with multiple different string values? for example, "Word that I want" and "Word that I want 2".

Thank you

Jason

• ###### 1. Re: How to write a dimension calculated field with a list of string values

Jason ,

You can use the concatenate sign  + .

"Word that I want" + "Word that I want 2"

And if you want to concatenate a Measure with a Dimension use can use the STR function  to  String your measure

"Sales for the month is: " +  str([sales])

Michel

• ###### 2. Re: How to write a dimension calculated field with a list of string values

Thanks for the reply Michel.

Sorry I wasn't clear enough. I actually wanted to see if there is a away to create a list like a discrete dimension with different characters string, not combining texts.

Jason

• ###### 3. Re: How to write a dimension calculated field with a list of string values

If you had a field that represented the various numbers, you could just concatenate the fields:

[WordThatIWant]+str([Number])

What is the use case for this?

• ###### 4. Re: How to write a dimension calculated field with a list of string values

Well if you want to create  a Row calculated field that put  a different word on each row , there must be some kind of logic behind.  For a given row , what condition determines if you use Word1 or Word2 ?

For example, if you would like to create a Dimension with possible values 'fruit' and 'vegetables' and you already have a row containing the Food type , you could have something like

if [FoodType] = 'Apple' or  [FoodType] = 'Orange' then 'Fruit'

elseif [FoodType] = 'Potato' or  [FoodType] = 'Onion' then 'Vegetable'

end

But i am not sure to understand exactly what you need

Michel

• ###### 5. Re: How to write a dimension calculated field with a list of string values

Hi Matthew,

I wanted to create a 3 side-by-side bar charts (2 different measures) in one worksheet (3 charts from top to bottom)

I figured that the only way to visualize this is to use calculated field to create 3 type names (which will go to the row) and use a Measure Names to select two measures (which are also two calculated fields with using if to show 6 different measures divided into two measures in each of the 3 type names).

• ###### 6. Re: How to write a dimension calculated field with a list of string values

I'm sorry, but I don't understand.  A mock up and some sample data loaded into a Tableau packaged workbook (.twbx file), along with a clear description of the view you want to build in Tableau would be most helpful.

• ###### 7. Re: How to write a dimension calculated field with a list of string values

Sorry I made it confusing.. I've attached the example file in the original post above.

I am trying to show what's in the dashboard with two worksheets using just one worksheet. If you see Orange & Apple worksheet, you will notice I tried doing that creating a dimension label but I don't know how to create one dimension that contains both "Orange" and "Apple".

• ###### 8. Re: How to write a dimension calculated field with a list of string values

Hi Michel.

If you could check my response to Matthew and have solution, that would be fantastic!..

• ###### 9. Re: How to write a dimension calculated field with a list of string values

Since your data source is an Excel sheet, some quick data prep would resolve your issues very simply.

Basically, you just want one column for the # value.  Then, another column that labels each row as either "Apple" or "Orange", and another column that labels each row as either "Mine" or "Yours".

Then, you'd have two dimensions -- "Fruit" and "Owner", lets say, and one measure, for the Value or #.  There is no dynamic way to create these dimensions from the data you have, inside of Tableau.

I believe your life would be much simpler if your data was structured properly for Tableau.

http://kb.tableausoftware.com/articles/knowledgebase/preparing-excel-files-analysis

Preparing Data for analysis with Tableau | Tableau Public

• ###### 10. Re: How to write a dimension calculated field with a list of string values

Jason,

I'm still confused,

In the  1 row example you attached,  on what condition did you set the label column to Orange, since on the same row you have  a value for MyApple and MyOrange?

• ###### 11. Re: How to write a dimension calculated field with a list of string values

I am actually using a big excel file (for me) with 100k rows and 50 columns, and apple and oranges (just examples here) are also calculated fields. So I want to avoid adding more columns or rearranging data (also wanted to avoid any manual work and just plug in what I receive as I have to update this every week).

But thank you very much for the answers Matthew.

• ###### 12. Re: How to write a dimension calculated field with a list of string values

The process I described would eliminate several columns (you'd be changing several columns into just a couple).

Best of luck--I think you'll find that getting the data ready prior to loading into Tableau is always ideal.

• ###### 13. Re: How to write a dimension calculated field with a list of string values

So I used case function to bring up "Mine" and "Yours" values. I am missing "Apple" in the Orange and Apple List Label, which is what I am trying to figure out how to do.