Azure AI in Business Central – The Forecasting Model

Azure AI in Business Central – The Forecasting Model

AI (Artificial Intelligence) can be used with Business Central; there are different possibilities of use and integration of Azure AI in Business Central.

The technology integrated with Business Central is based on Azure Machine Learning, Azure AI Framework, Subscription and Web Services.

Subscriptions for Business Central come with access to several predictive web services in all regions where Business Central is available. These web services are stateless, meaning they use data only to calculate predictions on demand, they do not store data.

#1 – The Azure machine learning model workflow

Azure Machine Learning Model Workflow diagram

The machine learning model workflow generally follows this sequence:

  1. Train – Help the machine learn.
  • Develop machine learning training scripts in Python, R, or with the visual designer.
  • Create and configure a compute target.
  • Submit the scripts to a configured compute target to run in that environment. During training, the scripts can read from or write to datastores. The logs and output that are produced during training are saved as runs in the workspace and then grouped under experiments.
  1. Package – After a satisfactory run is found, you will register the persisted model in the model registry.
  2. Validate – Query the experiment for logged metrics from the current and past runs. If the metrics don’t indicate a desired outcome, loop back to step 1 and iterate on your scripts.
  3. Deploy – Develop a scoring script that uses the model and then deploy the model as a web service in Azure or to an IoT Edge device.
  4. Monitor – Monitor for data drift between the training dataset and inference data of a deployed model. When necessary, loop back to step 1 to retrain the model with new training data.

Use Artificial Intelligence in Microsoft Dynamics 365 Business Central – Learn | Microsoft Docs

#2 – The Forecasting Model for Business Central

The Forecasting Model for Microsoft Dynamics 365 Business Central lets you analyze data in historical periods to make predictions about cash flow and inventory levels.

This model uses the Execute R Script module to run the R scripts that calculate the forecast and determine its accuracy.

The two input modules define the expected structure of the input datasets. The first module defines the historical data, and the second defines the global parameters.

Forecasting Model for Microsoft Dynamics 365 Business Central | Azure AI Gallery

Time Series Model

Create and use your own predictive web service for sales and inventory forecasts

You can also create your own predictive web service based on a public model named Forecasting model for Microsoft Business Central. This predictive model is available online in the Azure AI Gallery.

#3 – The Sales and Inventory Forecast Extension

We will now see one of the latest models released, very interesting because it relates to the supply chain, inventory management is a trade-off between customer service and managing your cost and useful for avoiding inventory Stock-Outs and for predicting restocking-

On one hand, a low inventory requires less working capital, but, on the other hand, stock-outs potentially lead to missed sales.

The “Sales and Inventory Forecast” extension predicts potential sales using historical data and gives a clear overview of expected stock-outs. Based on the forecast, the extension helps create replenishment requests to your vendors and saves you time.

Setting up Forecasting

In Business Central, the connection to Azure AI is already set up for you. But you can configure the forecast to use a different type of period to report by, such as changing from forecasting by month to forecasting by quarter. You can also choose the number of periods to calculate the forecast by, depending on how granular you want the forecast to be.

Consider the length of the periods that the service will use in its calculations. The more data you provide, the more accurate the predictions will be. Also, watch out for large variances in periods. They will also impact predictions. If Azure AI does not find enough data, or the data varies a lot, the service will not make a prediction.

Configure Model & Web Service

Using the Model

  • Open the experiment in Azure Machine Learning Studio.
  • Run it, and then deploy it as a web service.

In the web service dashboard:

  • Copy the API key
  • Choose REQUEST/RESPONSE, and then copy the Request URI.

Add the API key and the request URI in Dynamics 365 Business Central

No OData Endpoint is available for this Web Service

To support OData, the web service must have exactly one output and the type of that output must be DataTable. Also, default values must be present for all web service parameters; this web service has more than one output.

Web Service parameters (ex Python)

Name Parameters, Type Script

import urllib2

# If you are using Python 3+, import urllib instead of urllib2

import json

data = {

“Inputs”: {



“ColumnNames”: [“GranularityAttribute”, “DateKey”, “TransactionQty”],

“Values”: [ [ “value”, “0”, “0” ], [ “value”, “0”, “0” ], ]

}, },

“GlobalParameters”: {

“Parameters”: “”,



body = str.encode(json.dumps(data))

url = ‘<1213243544545>/execute?api-version=2.0&details=true’

api_key = ‘abc123’ # Replace this with the API key for the web service

headers = {‘Content-Type’:’application/json’, ‘Authorization’:(‘Bearer ‘+ api_key)}

req = urllib2.Request(url, body, headers)


response = urllib2.urlopen(req)

# If you are using Python 3+, replace urllib2 with urllib.request in the above code:

# req = urllib.request.Request(url, body, headers)

# response = urllib.request.urlopen(req)

result =


except urllib2.HTTPError, error:

print(“The request failed with status code: ” + str(error.code))

# Print the headers – they include the requert ID and the timestamp, which are useful for debugging the failure



For Sales & Inventory Forecast, search for Sales & Inventory Forecast Setup
  • Assign API URI and API KEY

Using the Forecasts

The extension uses Azure AI to predict future sales based on your sales history to help you avoid inventory shortage. For example, when you choose an item on the Items page, the chart in the Item Forecast pane shows the estimated sales of this item in the coming period. This way you can see if you are likely to run out of stock of the item soon. You can also use the extension to suggest when to stock up on inventory.

Data required for forecast

To make predictions about future sales, the web service requires quantitative data about past sales. That data comes from the Posting DateItem No, and Quantity fields on the Item Ledger Entries page, where:

  • The entry type is “Sale
  • The posting date is between the date that is calculated based on the values in the Historical Periods and Period Type fields on the Sales and Inventory Forecast Setup page and the work date.

Before using the web service Business Central compresses transactions by Item No. and Posting Date based on the value in the Period Type field in the Sales and Inventory Forecast Setup page.


Search for “Sales and Inventory Forecast Setup”

Open “Sales and Inventory Forecast Setup”

Schedule automatic update

You can schedule the update automatically through Job Queue Process

Forecast On-Demand Update

Or you can run an OnDemand update for Forecast, search for “Update Forecast”

Now open the “Item List page”

The Forecast FastTab will look similar to the following image:

With “Show Inventory Forecast” it is possible to see the forecast calculated on the inventory

..but If you have no historical data for items…

This message means that not enough historical data is available to help predict future sales. You need at least five periods of historical sales to predict future sales.

The forecast data will not be displayed (but only calculated) if there is not enough data for forecast calculation or if the calculated data is not significant as it is outside the 20-40 of variance.

You can try to create some sales, purchase and inventory type entries to test the forecast calculation, if the extraction remains in the configured variance, the Forecast data are displayed in Item Forecast FastTab.

Forecast calculation update from “Item List”

It’s possible to update the forecast calculation also from the item list 🡪 “Update Sales Forecast”

With Forecast FastTab you can “Create Purchase Orders and Purchase Invoices”

From the Forecast FastTab you can create Purchase Orders and Purchase Invoices from the data calculated by the Forecast, and change the forecast setup.

#4 – Others Azure AI Models Ready-to Use

There are other Azure AI models already available for you to try:

Screenshot of a Cash flow forecast chart.

Set up cash flow forecasts by using Azure AI – Learn | Microsoft Docs

Modello Esperimento di previsione per Dynamics 365 Business Central.

Predict late payments for sales documents in Dynamics 365 Business Central – Learn | Microsoft Docs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.