Predictive Modeling and Type Conversion Function in Tableau

Predictive Modeling and Type Conversion Function in Tableau

6 mins read345 Views Comment
Vikram
Vikram Singh
Assistant Manager - Content
Updated on Jun 28, 2022 08:52 IST

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.

2022_06_feature-images_PREDICTIVE-MODELING.jpg

Table of Content

Recommended online courses

Best-suited Tableau courses for you

Learn Tableau with these high-rated online courses

39.54 K
2 hours
– / –
45 hours
– / –
4 weeks
– / –
4 weeks
2.25 K
4 weeks
Free
12 hours
– / –
1 hours
19.89 K
16 hours
– / –
3 hours
19.7 K
6 months

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
2022_06_Predict-median-value.jpg

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
2022_06_prediction-calculation-function-in-tableau.jpg

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

2022_06_Predict-median-value.jpg

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.
How to Create a Forecast in Tableau
How to Create Hierarchies in Tableau
How to Create Group in Tableau

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
2022_06_string-order-date-in-tableau.jpg

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:
2022_06_Date-Data-type-conversion-function.jpg

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:
2022_06_datetime_data-type-conversion-function.jpg

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:
2022_06_dateparse_datatype-conversion-function.jpg

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:
2022_06_float_data-type-conversion-function.jpg

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:
2022_06_INT_datatype-conversion-function.jpg

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:
2022_06_string-order-date-in-tableau.jpg

The above formula will change the data type of Order Date from Date Data Type to String Data Type.

Level of Detail(LOD) Expression in Tableau
How to Create Calculated Field in Tableau
Sort Data in Tableau
About the Author
author-image
Vikram Singh
Assistant Manager - Content

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