How to perform String Calculations in Tableau?

String functions allow you to manipulate string data (i.e. data made of text).

Follow along with the steps below to learn how to create a string calculation.

  1. In Tableau Desktop, connect to the Sample - Superstore saved data source, which comes with Tableau.
  2. Navigate to a worksheet.
  3. From the Data pane, under Dimensions, drag Order ID to the Rows shelf.
  4. Notice that every order ID contains values for the country (CA and US, for example), year (2011), and order number (100006). For this example, you will create a calculation to pull only the order number from the field.
  5. Select Analysis > Create Calculated Field.
  6. In the calculation editor that opens, do the following:

Name the calculated field Order ID Numbers.

Enter the following formula:

  • RIGHT([Order ID], 6)
  • This formula takes the specified digits (6) from the right of the string and pulls them into a new field.
  • Therefore, RIGHT('CA-2011-100006' , 6) = ‘100006’.
  • When finished, click OK.
  • The new calculated field appears under Dimensions in the Data pane. Just like your other fields, you can use it in one or more visualizations.

From the Data pane, drag Order ID Numbers to the Rows shelf. Place it to the right of Order ID.