Data Types and Operators in Tableau
Data Connection with Data Sources in Tableau
- Tableau allows easy data connection with text files and Excel files. It also provides powerful calculation features using functions, fields, operators, literals, parameters, and comments to create meaningful data analysis.
- Tableau allows users to connect to various data sources such as text files, Excel files, databases, and cloud services. Connecting data is the first step before creating visualizations.
- Connecting to a Text File
- A text file includes formats such as .csv or .txt.
- Step1: Open Tableau.
- Step2: Click Text File under “Connect”.
- Step3: Select the required .csv or .txt file.
- Step4: Tableau loads the data into the Data Source page.
- Step5: Click Sheet to start creating visualizations.
- Step6: Text files are commonly used for simple datasets.
- A text file includes formats such as .csv or .txt.
- Connecting to Microsoft Excel
- Tableau can connect directly to Excel files (.xls, .xlsx).
- Step1: Open Tableau.
- Step2: Click Microsoft Excel under “Connect”.
- Step3: Select the Excel file.
- Step4: Choose the required worksheet from the Excel file.
- Step5: Load the data and start analysis.
- Step6: Excel is widely used for business and academic datasets.
- Tableau can connect directly to Excel files (.xls, .xlsx).
- Connecting to a Text File
Components of Tableau Calculations
- Tableau provides a calculation feature to create new data fields using formulas.
- A calculated field is created using functions, operators, parameters, and other components. Some common are –
- Function
- Functions are predefined formulas used to perform operations.
- Examples: SUM(), AVG(), IF THEN ELSE, DATE functions, etc.
- Field
- A field is a column from the data source used in calculations.
- Example: [Profit]
- Operator
- Operators are symbols used to perform operations.
- Common Types:
- Arithmetic: +, -, *, /
- Comparison: =, >, <
- Logical: AND, OR, NOT
- Example: [Sales] – [Cost]
- Literal
- A literal is a fixed value used in a calculation.
- Examples: Number: 100, Text: “High”, Date: #2024-01-01#
- Example: [Sales] > 1000
- Parameter
- A parameter is a dynamic value that users can change.
- It allows interactive calculations.
- Example:
- [Sales] > [Target Parameter]
- Comment
- Comments are notes added inside a calculation for explanation.
- Single-line comment: // This calculates profit margin.
- Multi-line comment:
- Function
Data Types in Tableau
- In Tableau, data types define the nature of the values stored in fields and columns.
- It is crucial to understand data types for proper data analysis, visualization, and manipulation within Tableau.
- Automatic or Dynamic Data Type :
- Tableau automatically assigns data types to fields based on the data source and its inferred structure. However, users can manually override data types as needed.
- Data Type Conversion:
- Tableau allows users to convert data types as needed within calculated fields or during data preparation using functions like INT(), STR(), DATE(), etc.
(A) The broad categories of data types supported by Tableau are:
1. Numeric Data Types: These include-
-
- Integer (Whole Number): This data type represents whole numbers without decimal points.
- Float (Floating-Point Number): This data type represents numbers with decimal points.
- Decimal: This data type represents precise numeric values with fixed decimal precision.
2. String Data Types: These include-
-
- String (Text): This data type represents text or alphanumeric characters.
- Char (Character): This data type is a fixed-length character string.
- Varchar (Variable Character): This data type is a variable-length character string.
3. Date and Time Data Types: These include-
-
- Date: This data type represents dates without time information.
- DateTime (Date and Time): This data type represents both date and time information.
- Time: This data type represents time information without dates.
- Timestamp: This data type represents date and time with timezone information.
4. Boolean Data Type: These include-
-
- Boolean (Logical): This data type represents true or false values.
5. Geographic Data Types: These include-
-
- Latitude: This data type represents the latitude coordinate.
- Longitude: This data type represents the longitude coordinate.
- Geographic Role: Tableau provides specific geographic roles for geographic data, such as country, state, city, etc.
6. Other Data Types: These include-
-
- Binary: This data type represents binary data, such as images or files.
- Object: This data type represents any data type that cannot be classified into other specific types.
(B) Additional Data Type in Tableau:
-
- Discrete vs. Continuous Data:
- In Tableau, data types can be further categorized as discrete or continuous.
- Discrete data types represent distinct, separate values (e.g., integers, dates), while continuous data types represent a range of values (e.g., floats, time durations).
- Discrete vs. Continuous Data:
Operators in Tableau
- In Tableau, operators are symbols or keywords used to perform specific operations or comparisons on data in expressions, calculations, or conditions.
- Operators in Tableau are used to perform calculations, comparisons, and logical operations within calculated fields and formulas.
- These operators help in data transformation, filtering, and decision-making.
- These are some of the commonly used operators in Tableau. They are used in calculated fields, filters, and other expressions to perform calculations, comparisons, and logical operations on data.
Types of Operators in Tableau
- Tableau provides General, Arithmetic, Relational, and Logical operators to create powerful calculations and filters in dashboards. They are categorized into the following types:-
1. General Operators
- These operators are common operators used in Tableau calculations:
| Operator | Description | Example | Result |
| + | Addition or String Concatenation | 5 + 3 | 8 |
| – | Subtraction | 10 – 4 | 6 |
| * | Multiplication | 7 * 2 | 14 |
| / | Division | 10 / 2 | 5 |
| % | Modulus (Remainder) | 10 % 3 | 1 |
| ^ | Power/Exponentiation | 2 ^ 3 | 8 |
2. Arithmetic Operators
- These operators are used to perform mathematical operations on numeric data.
| Operator | Description | Example | Result |
| + | Addition | [Sales] + 100 | Sales increased by 100 |
| – | Subtraction | [Profit] – 50 | Profit reduced by 50 |
| * | Multiplication | [Quantity] * 2 | Quantity doubled |
| / | Division | [Revenue] / 2 | Revenue divided by 2 |
| % | Modulus (Remainder) | [Order ID] % 2 | Returns remainder |
3. Relational (Comparison) Operators
- These operators are used to compare two values.
- They return TRUE or FALSE.
| Operator | Description | Example | Result |
| = | Equal to | [Region] = “West” | TRUE if the Region is West |
| != or <> | Not equal to | [Category] != “Furniture” | TRUE if the Category is not Furniture |
| > | Greater than | [Profit] > 1000 | TRUE if Profit is greater than 1000 |
| < | Less than | [Discount] < 0.2 | TRUE if the Discount is below 20% |
| >= | Greater than or equal to | [Sales] >= 500 | TRUE if Sales is 500 or more |
| <= | Less than or equal to | [Quantity] <= 10 | TRUE if Quantity is 10 or less |
4. Logical Operators
- These operators are used to combine multiple conditions.
| Operator | Description | Example | Result |
| AND | Returns true if both conditions are true | [Sales] > 500 AND [Profit] > 100 | TRUE if both are met |
| OR | Returns true if at least one of the conditions is true. | [Category] = “Furniture” OR [Category] = “Office Supplies” | TRUE if the Category is Furniture or Office Supplies |
| NOT | Reverses a condition or negates the result of a condition. | NOT ([Region] = “South”) | TRUE if the Region is not South |
5. String Operators
- + CONCATENATION: It concatenates two or more strings.
- CONTAINS: It checks if a string contains a specified substring.
- STARTSWITH: It checks if a string starts with a specified prefix.
- ENDSWITH: It checks if a string ends with a specified suffix.
- LIKE: It performs a pattern match comparison on strings.
6. Date & Time Operators
- DATEDIFF: It returns the difference between two dates.
- DATETRUNC: It truncates a date to a specified level of granularity (e.g., year, month).
- DATEADD: It adds a specified interval to a date.
7. Aggregate Operators
- SUM(): It returns the sum of a set of values.
- AVG(): It returns the average of a set of values.
- MIN(): It returns the minimum value in a set.
- MAX(): It returns the maximum value in a set.
- COUNT(): It returns the count of non-null values in a set.
8. Set Operators
- UNION: It combines two sets of data
- INTERSECT: It returns the intersection of two sets of data
- EXCEPT: It returns the difference between two sets of data
9. Conditional Operators:
- IF Conditional statement: It returns one value if a condition is true and another value if it’s false
10. Case Statement:
-
CASE Statement: It is used for conditional logic similar to the switch-case statement in programming languages
11. Table Calculation Operators:
-
WINDOW_SUM: It calculates a sum across a specified window of data.
-
RUNNING_SUM: It calculates a running sum of values in a specified order.
![]()
0 Comments