In Tableau, calculated fields allow you to create new data by performing calculations on your existing data. There are several types of calculated fields you can create:
1. Basic Calculations
These are simple arithmetic operations on data fields. You can perform basic operations like addition, subtraction, multiplication, and division.
- Example:
Profit = Sales - Cost
2. String Calculations
String calculations manipulate text data. You can concatenate strings, change case, find substrings, or replace parts of a string.
- Example:
Full Name = [First Name] + ' ' + [Last Name]
3. Date Calculations
These calculations help you manipulate and work with date fields. You can extract parts of dates (like year, month), calculate the difference between two dates, or even create dynamic date ranges.
- Example:
DATEDIFF('year', [Start Date], [End Date])
4. Logical Calculations
Logical calculations allow you to create conditions using IF
, THEN
, ELSE
, and CASE
statements to evaluate data.
- Example:
IF [Sales] > 1000 THEN 'High' ELSE 'Low' END
5. Aggregated Calculations
These calculations use aggregation functions like SUM()
, AVG()
, MIN()
, MAX()
, and COUNT()
to summarize data across multiple records.
- Example:
SUM([Sales]) / COUNT([Orders])
6. Table Calculations
These are calculations that work across rows or columns in the table and are based on the result of the view. They include functions like RUNNING_SUM()
, WINDOW_AVG()
, and RANK()
.
- Example:
RUNNING_SUM(SUM([Sales]))
7. Level of Detail (LOD) Calculations
LOD expressions allow you to compute values at different levels of granularity, independent of the view’s aggregation.
- Types:
- FIXED: Fixed at a specific level.
- INCLUDE: Adds more dimensions to the view.
- EXCLUDE: Ignores specific dimensions.
- Example:
{ FIXED [Region] : SUM([Sales]) }
8. Number Calculations
These calculations work with numerical data for advanced mathematical operations like rounding, modulus, trigonometric functions, logarithms, etc.
- Example:
ROUND(SUM([Sales]), 2)
9. Blended Calculations
When using data blending (combining data from multiple sources), you can create calculated fields that perform operations across these blended data sets.
- Example:
SUM([Dataset1].[Sales]) + SUM([Dataset2].[Sales])
10. Spatial Calculations
These calculations are used for working with geographic data. Functions like DISTANCE()
, MAKEPOINT()
, and MAKELINE()
allow you to calculate distances and create spatial visualizations.
- Example:
DISTANCE([Location 1], [Location 2], "km")
Each type of calculation provides specific functionality to manipulate and analyze your data more effectively in Tableau.