Predictive Modeling and Type Conversion Function in Tableau
In this article, we will discuss different predictive and data type conversion functions in tableau with the help of examples. We will also discuss how to create predictive and data type conversion function in Tableau.
Table of Content
Best-suited Tableau courses for you
Learn Tableau with these high-rated online courses
Predictive Modeling Function
Why use the Predictive Modeling Function?
In Tableau, Predictive Modeling Function is a significant statistical modeling tool that enables the building and updating of predictive models. It allows for finding the relationship between the data, estimating the missing data, and projecting data into the future.
The predictive modeling function allows selecting your own target and predictors by updating the variables and visualizing multiple models with different combinations of predictors.
Now, you don’t need to write any Python or R codes to perform any advanced statistical calculation to visualize the valuable insights from the data, you can directly use different predictive modeling functions to perform these statistical calculations.
Must Check: What is Tableau?
Must Check: Tableau Online Courses & Certifications
Now, we will see how to create a Predictive Modelling Function in Tableau
Create a Prediction Calculation
We will understand how to create prediction calculations with the help of an example using Sample Superstore data.
Problem Statement: Predict the median profit (monthly) of sample superstore data.
- Connect the Sample Superstore Data
- Drag and Drop Order Date to the column shelf
- Right-click on Order Date -> Month
- Drag and Drop Profit to the row shelf
- Select Analysis -> Create Calculated Field
- Enter the name “Predict Median Profit”
- Enter the formula
Note: The above formula will use the second quantile (i.e. median) and predict the value based on the Predictors (Here Order Date) we input.
- Click OK
- The new calculated field (Predict Median Profit) appears in Data Pane under the measure
- Drag and Drop Predict Median Profit to the row shelf
- Right-click on Predict Median Profit -> Dual Axis
- Align the axis
- Right Click on Predict Median Profit (in the view) -> Select Synchronize Axis
The above images show the prediction of median profit using the order date as a predictor.
Predictive Modeling Function
MODEL_QUANTILE
- It will return an expected value (target numeric value) at a specified quantile within the probable range
- Used to generate a Confidence Interval, and missing values
- Syntax: MODEL_QUANTILE(model_specification (optional), quantile, target_expression, predictor_expression(s))
Example: Predict the median profit
The above formula will predict the median profit using the order date as a predictor.
MODEL_PERCENTILE
- Calculates the Cumulative Distribution Function (CDF)
- Calculates the quantile of a particular value between 0 and 1
- It is the inverse of MODEL_QUANTILE
- Syntax: MODEL_PERCENTILE(model_specification (optional), target_expression, predictor_expression(s))
Rules for Prediction Calculation
- Aggregate and non-aggregate arguments can’t be combined
- If the target expression is aggregate, then the predictor must be aggregate
- The function should use a Predictor that is of the same level of detail or higher
- Functions are best used to predict values for:
- Individual records where each mark represents a discrete entity like a person, product, sale, etc
- Aggregate target expression using SUM and COUNT
- Functions are not recommended to predict values for target expression using AVG, MEAN, MEDIAN, MAX, MIN, etc.
Type Conversion Function
Why use the Type Conversion Function?
In Tableau, we can convert the data type of one field to another data type. Using the data conversion function we can change integer or date data type to string data type so that Tableau doesn’t try to aggregate them. Similarly, we can change the string data type to date or integer data type to activate aggregation by tableau.
Now, we will see how to create an aggregation calculation in Tableau.
Create a Type Conversion Calculation
We will understand how to create Type Conversion Calculations with the help of an example using Sample Superstore data.
Problem Statement: Change the data type of Order Date from date data type to String data type.
Steps to Create
- Connect the Sample Superstore data
- Select Analysis -> Create Calculated Fields
- Enter the name “String Order Date”
- Write the Formula
The above formula will change the data type of Order Date from Date Data Type to String Data Type
- Click OK
- The new calculated field (String Order Date) appears in Data Pane under the measure
Note: Now, tableau will treat String order Date as a string, not a date, and will not aggregate it.
Type Conversion Function
DATE
- It will return the date if the expression is a string, number, or date itself
- Syntax: DATE (expression)
- Example:
The above expression will return #June 28, 2022#. It converts string data type to date data type function.
DATETIME
- It is similar to the DATE function, but in addition to date it will also return time i.e. it will return date and time if the expression is a string, number, or date itself
- Syntax: DATETIME (expression)
- Example:
The above expression will return June 28, 2022 07:59:00. It converts string data type to date data type function.
DATEPARSE
- It will convert a string to a Date Time in the user-defined format
- The defined format must be a constant string, not a field value, and will return NULL if the data does not match the format
- Syntax: DATEPARSE (format, string)
- Example:
The above expression, will return #07 : 59 : 00#. It convert the given string into date but the format defined by the users (here in HH : MM: SS).
FLOAT
- It will return the user-defined expression into a floating-point value
- Syntax: FLOAT (expression)
- Example:
The above formula will return 3.000. In simple term it will convert the given value into decimal value.
INT
- It will return the user-defined expression into an Integer
- It is similar to the floor function of mathematics
- i.e. it truncates results to the integer less than or equal to the closet integer value
- Syntax: INT (expression)
- Example:
The above formula will return the value 3.
Note: When any string is converted using the INT function, then it will be first converted to float and then rounded
STR
- It will return the user-defined expression into a String
- Syntax: STR (expression)
- Example:
The above formula will change the data type of Order Date from Date Data Type to String Data Type.
Conclusion
In this article, we have discussed different predictive and data type conversion functions in tableau with the help of examples. We also discussed how to create predictive and data type conversion function in Tableau.
Hope this article, will help you in your data analytics journey.
Top Trending Articles:
Introduction To Tableau | Products Of Tableau | Data Types In Tableau | Change Data Type In Tableau | File Type In Tableau | Data Aggregation | Connecting Data In Tableau | Dimension And Measure | Tableau Show Me | Joins In Tableau | Union In Tableau | Operators In Tableau | Number Functions In Tableau | String Functions In Tableau | Filter In Tableau | Context Filter In Tableau | Filters In Tableau | Types Of Charts In Tableau | Bar And Line Chart In Tableau | Pareto Chart In Tableau | Gantt Chart In Tableau | Box And Whisker Chart In Tableau | Waterfall Chart In Tableau | Donut Chart In Tableau | Funnel Chart In Tableau | Dual Axis Chart In Tableau | Sort Data In Tableau | Tableau Sets | Groups In Tableau | Tableau Hierarchy | Tableau Forecasting | Highlighting In Tableau | Word Cloud In Tableau | Cohort Analysis In Tableau
Vikram has a Postgraduate degree in Applied Mathematics, with a keen interest in Data Science and Machine Learning. He has experience of 2+ years in content creation in Mathematics, Statistics, Data Science, and Mac... Read Full Bio