Để xem tổng số tương ứng với các số bạn thấy trong chế độ xem của bạn yêu cầu hai thao tác lấy trung bình trong Tableau: trước tiên, các giá trị cho các dấu riêng lẻ [hoặc ô] trong chế độ xem phải được dẫn xuất, ví dụ, bằng cách lấy trung bình tất cả các giá trị có thuộc tính Ship Mode = First Class, Category = Furniture, and Region = Central. Sau đó, các kết quả cho từng khu vực phải được lấy, bằng cách lấy trung bình các kết quả cho các nhãn hiệu riêng lẻ. May mắn thay, bạn không cần phải thực hiện hai thao tác. Để hiển thị kết quả của loại này, từ menu Analysis, chọn Totals > Total All Using > Average. Bây giờ, mức trung bình được thực hiện trên các giá trị bạn nhìn thấy và không phải vào ngày phân tách trong nguồn dữ liệu:
This article introduces string functions and their uses in Tableau. It also demonstrates how to create a string calculation using an example.
Why use string functions
String functions allow you to manipulate string data [i.e. data made of text]. Tableau uses the current International Components for Unicode [ICU] library when comparing strings. The way strings are sorted and compared is based both on language and locale, and it’s possible for vizzes to change as the ICU is continuously updated for better language support.
For example, you might have a field that contains all of your customers' first and last names. One member might be: Jane Johnson. You can pull the last names from all your customers into a new field using a string function.
The calculation might look something like this:
SPLIT[[Customer Name], ' ', 2]
Therefore, SPLIT['Jane Johnson' , ' ', 2] =
'Johnson'.
String functions available in Tableau:
Function | Syntax | Definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASCII | ASCII[string]
| Returns the ASCII code for the first character of Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CHAR | CHAR[number]
| Returns the character encoded by the ASCII code Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CONTAINS | CONTAINS[string, substring]
| Returns true if the given string contains the specified substring. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ENDSWITH | ENDSWITH[string, substring]
| Returns true if the given string ends with the specified substring. Trailing white spaces are ignored. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FIND | FIND[string, substring, [start]]
| Returns the index position of Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FINDNTH | FINDNTH[string, substring, occurrence]
| Returns the position of the nth occurrence of substring within the specified string, where n is defined by the occurrence argument. Note: FINDNTH is not available for all data sources. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LEFT | LEFT[string, number]
| Returns the left-most number of characters in the string. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LEN | LEN[string]
| Returns the length of the string. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOWER | LOWER[string]
| Returns Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LTRIM | LTRIM[string]
| Returns the string with any leading spaces removed. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MAX | | Returns the maximum of Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MID | [MID[string, start, [length]]
| Returns the string starting at index position Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MIN | MIN[a, b]
| Returns the minimum of Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REPLACE | REPLACE[string, substring, replacement]
| Searches Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RIGHT | RIGHT[string, number]
| Returns the right-most number of characters in Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RTRIM | RTRIM[string]
| Returns Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SPACE | SPACE[number]
| Returns a string that is composed of the specified Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SPLIT | SPLIT[string, delimiter, token number]
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
STARTSWITH | STARTSWITH[string, substring]
| Returns true if Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TRIM | TRIM[string]
| Returns the string with leading and trailing spaces removed. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
UPPER | UPPER[string]
| Returns string, with all characters uppercase. Example: |
Create a string calculation
Follow along with the steps below to learn how to create a string calculation.
In Tableau Desktop, connect to the Sample - Superstore saved data source, which comes with Tableau.
Navigate to a worksheet.
From the Data pane, under Dimensions, drag Order ID to the Rows shelf.
Notice that every order ID contains values for 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.
Select Analysis > Create Calculated Field.
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.
Notice how the fields differ now.
See Also
Functions in Tableau
Tableau Functions [Alphabetical]
Tableau Functions [by Category]
Formatting Calculations in Tableau