# Forecasting Model for Microsoft Dynamics 365 Business Central

Use reliable forecasts to proactively manage your cash flow and inventory levels. Predict and be ready for high times and low

Using Model
===========
- Open this 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.
Example API key:
EXAMPLE42mSIPm4xkBqFuE8/8IiFxpRQI777wekuHu6YIPLmfe7WCrQpqWqvyOr1n8reaA517DaE5888GbSg==
- Choose REQUEST/RESPONSE, and then copy the Request URI.
Example endpoint URI:
https://ussouthcentral.services.azureml.net/workspaces/xyz/services/xyz/execute?api-version=2.0&details=true
- Add the API key and the request URI in Dynamics 365 Business Central:
1. For **Sales & Inventory Forecast**, search for **Sales & Inventory
Forecast Setup**
2. For **Cash Flow Forecast**, search for **Cash Flow Setup**.
Model
-----
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.
![enter image description here][1]
Input Data Schema
-----------------
The experiment uses historical time series values from the following fields:
- **GranularityAttribute (String)** - Can be associated with a product ID to forecast product sales. The Group ID can be a composite key that includes the product ID and a location ID or variant.
- **DateKey (Numeric)** - Ordinal number of time-periods, such as days, weeks, months, or years. The model expects the same duration for each period.
- **TransactionQty (Numeric)** - The forecast value for the quantity of items sold, total payables or receivables, or the percentage of capacity that was used.
Additionally, the model requires a set of parameters for modules:
- **Horizon (Numeric)** - Specifies the number of future periods to make predictions for.
- **Seasonality (Numeric)** – The model accepts any type of time-period, but if you want it to recognize seasonality you need to define what a normal season is for the historical data. For example, if the season is a year and the values are grouped monthly, then seasonality should be 12. If the season contains quarterly values, then seasonality should be 4. However, if seasonality in your business is weekly, use 7 and aggregate values daily.
- **Forecast_start_datekey (Numeric)** – Specifies a delay before forecasting starts.
Here’s an example. Today is January 1st, and your data is for the past year, which is 12 periods. You can enter 2 as the **Horizon**, and 15 for **Forecast_start_datekey**. In this case, you skip two months, and get predictions for March and April.
You can achieve the same result by specifying 4 as the **Horizon**, and skipping the first 2 periods when processing the response. In this case, specify **Forecast_start_datekey** as the last value of **DateKey** field, and increment it by 1. For example, if you provide twelve months of historical data, and the last **DateKey** is 12, the **Forecast_start_datekey** will be 13 (12+1).
- **Time_series_model (String)** - Specifies the time series model to use. The model supports the following algorithms, and combinations of them:
1. ARIMA
2. ETS
3. STL
4. ETS+ARIMA (returns average as result)
5. ETS+STL (returns average as result)
6. ALL
7. TBATS
If you choose ALL the model compares the results and returns the one that has the lowest mean absolute percentage error (MAPE).
- **Confidence_level (Numeric)** - In the model output, notice that in addition to
the forecasted value, the model also returns the sigma, or variance.
This is the range that future values are predicted to fall within,
with the probability defined by the confidence level. So, if the
confidence level is 95%, the forecasted value might be 100, for
example, and the sigma 20. This means that with a probability of 95%,
the actual value will be somewhere in between 80 and 120 (100+/-20).
If you set the **confidence_level** to 85, the sigma will be lower. In
the example above, it can be that the forecasted value is 100 and the
sigma 14. Together, this means that, with a probability of 85%, the
actual value will be somewhere between 86 and 114.
Output Data Schema
------------------
The output of the service shows the calculated forecast values with confidence levels in the following fields:
- **GranularityAttribute (String)** - Can be associated with a product ID to
forecast product sales.
- The **DateKey (Numeric)** field – Ordinal number of the forecasted time-period.
For example, if you provide twelve months of historical data, and
the last **DateKey** is 12, and the horizon is 3, the model returns
three sequential DateKey values, 13, 14 and 15, for each GranularityAttribute.
- The **TransactionQty (Numeric)** – The forecast value for the quantity of items sold, total payables or receivables, or the percentage of capacity that was used.
- The **Sigma (Numeric)** – Specifies the range that the forecast values are expected to fall within. This
indicates the quality of predictions. For example, if **TransactionQty**
is 100, and **Sigma** is 10, the forecast value will be somewhere between
90 and 110. This is a good prediction. If Sigma is 100, however, the
forecast value will be between 0 and 200, which is not a reliable
prediction.
[1]: https://msdnshared.blob.core.windows.net/media/2016/10/DynamicsNAVTimeSeriesModel.png