---
schema_version: "1"
id: 4bb49732a57574d5001dc419133bf9072900fe99a8816ab0fd255d3510e53452
title: Predictive Modelling Functions
collection: tableau
version: current
locale: en-gb
portal_url: https://docs.salesforce.com/tableau/current/en-gb/pro/desktop/functions_functions_predictivemodeling.md
canonical_url: https://help.tableau.com/current/pro/desktop/en-gb/functions_functions_predictivemodeling.htm
source_site: help.tableau.com
content_type: documentation
content_hash: 51c333238bdbd21e8c16a73ab17723cbc15f11a73af3b1c25e279b217ce35ceb
description: Reference for predictive modeling functions MODEL_PERCENTILE and MODEL_QUANTILE.
---
[Skip to main content](#main-content)

# Predictive Modelling Functions

This article introduces predictive modelling functions and their uses in Tableau. It also demonstrates with an example how to create table calculations using the predictive modelling functions.

## Why use predictive modelling functions

Predictive modelling functions can help you quickly generate predictions that can be manipulated, visualised and exported like data using [table calculations](https://help.tableau.com/current/pro/desktop/en-gb/calculations_tablecalculations.htm).

Before, you may have had to integrate Tableau with R and Python in order to perform advanced statistical calculations and visualise them in Tableau. Now, you can select targets and predictors by updating the variables and visualising multiple models with different combinations of predictors. The data can be filtered, aggregated and transformed at all levels of detail, with inputs and predictions automatically recalculated to match the data in the view.

For more information about predictive modelling functions in Tableau, see [How Predictive Modelling Functions Work in Tableau](https://help.tableau.com/current/pro/desktop/en-gb/predictions_overview.htm)

## Predictive modelling functions available in Tableau

### MODEL\_PERCENTILE

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MODEL_PERCENTILE(
							<br>model_specification (optional),
							<br>target_expression,
						<br>predictor_expression(s))</code></td></tr><tr><td>Definition</td><td>Returns the probability (between 0 and 1) of the expected value being less than or equal to the observed mark, defined by the target expression and other predictors. This is the Posterior Predictive Distribution Function, also known as the Cumulative Distribution Function (CDF).</td></tr><tr><td>Example</td><td><pre>MODEL_PERCENTILE( SUM([Sales]),COUNT([Orders]))</pre></td></tr></tbody></table>

### MODEL\_QUANTILE

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MODEL_QUANTILE(
						<br>model_specification (optional), 
						<br>quantile, 
					    <br>target_expression,
						<br>predictor_expression(s))</code></td></tr><tr><td>Definition</td><td>Returns a target numeric value within the probable range defined by the target expression and other predictors, at a specified quantile. This is the Posterior Predictive Quantile.</td></tr><tr><td>Example</td><td><pre>MODEL_QUANTILE(0.5, SUM([Sales]), COUNT([Orders]))</pre></td></tr></tbody></table>

## Create a prediction calculation

Follow along with the steps below to learn how to create a simple prediction calculation using the MODEL\_QUANTILE function. For a more detailed example, see [Example – Explore Female Life Expectancy with Predictive Modelling Functions](https://help.tableau.com/current/pro/desktop/en-gb/predictions_example.htm)

### Step 1: Create a Visualisation

1. In Tableau Desktop, connect to the **Sample - Superstore** saved data source, which comes with Tableau.
2. Navigate to a worksheet.
3. From the **Data** pane, drag the Order Date dimension to the Columns shelf.
4. Open the measure’s context menu to change its list level to Month and Year:
    
    ![A dropdown menu displaying various date format options.](/tableau/current/en-gb/pro/desktop/en-gb/Img/predict-pill-list-level.png)
5. Drag Sales to the Rows shelf.

### Step 2: Create the Calculated Field

1. Click to open the Analysis menu at the top, and then select Create Calculated Field.
2. In the Calculation Editor, do the following:

- Name the calculation: **Predict Median Sales.**
- Enter the following formula:
    
    MODEL\_QUANTILE(0.5, SUM(\[Sales\]),ATTR(DATETRUNC('month', \[Order Date\])))
    
    Remember: The MODEL\_QUANTILE function takes a given quantile and predicts values based on the predictors you input.
    
    Let's break this down:
    
    - In this case, the quantile = 0.5, which predicts the median.
    - We want to predict sales, so the target expression is SUM(\[Sales\]).
    - We want to base the prediction on past performance, so we include date as a predictor, which is the last argument in the calculation.

4. When finished, click OK.

The prediction calculation is now added as a calculated field in the Data pane.

### Step 3: Add the Prediction Calculation to the View

1. Drag the prediction calculation to the Rows shelf, to the right of SUM(Sales).
2. Right-click (Control-click on Mac) the measure and select Dual Axis.
3. To align the two axes in a dual axes chart to use the same scale, right-click (Control-click on Mac) the secondary axis, in this case Predict Median Sales, and select Synchronise Axis. This aligns the scale of the two axes.

![A line chart comparing projected median sales to actual sales from 2017 to 2021.](/tableau/current/en-gb/pro/desktop/en-gb/Img/viz-with-prediction.png)

That's all there is to it. To find out how you can extend a date axis and predict the future, see [Predictive Modelling Functions in Time Series Visualisations](https://help.tableau.com/current/pro/desktop/en-gb/predictions_future.htm).

## Rules for Prediction Calculations

- You can’t mix aggregate and non-aggregate arguments. If the target expression is an aggregate, so must the predictor.
- The functions are best used to predict values for individual records, on vizzes where each mark represents a discrete entity, such as a person, a product, a sale, etc.
- The functions are best used to predict values for aggregated target expressions using SUM and COUNT.
- The functions aren’t recommended to predict values for aggregated target expressions using AVG, MEDIAN, MIN or MAX.
- The functions should use predictors that are at the same level of detail or higher than the viz.