How Dynamics 365 Business Central Automates Receivables Account Selection for Multi-Product Finance Teams - CloudFronts

How Dynamics 365 Business Central Automates Receivables Account Selection for Multi-Product Finance Teams

Summary

When machine learning models predict demand from Microsoft Dynamics 365 Business Central data, the biggest issue is usually not the algorithm. It is that ERP systems were built for accounting, not data science. While building an automated data pipeline across 12 Business Central tables on Azure Databricks, we ran into three silent traps: the Ghost in the Warehouse (confusing what shipped with what customers wanted), the Negative Demand Paradox (returns and credit memos distorting seasonal patterns), and the Missing Days Dilemma (days with zero sales disappearing from the data). Here is what each one looks like in real tables, and how we solved them with PySpark.

ERP Data Is Never Clean

An ERP system like Business Central is designed to keep the books balanced and track physical stock. It was not designed with machine learning in mind.

When we built a demand forecasting pipeline for a distributor of educational equipment and furniture, we pulled in 12 tables from Business Central, including sales headers, sales lines, item ledger entries and warehouse locations, plus a separate table for exceptions such as returns.

At first glance, the data looks clean. Quantities are recorded, dates are logged and invoices are posted. Underneath, there are three logical traps that quietly ruin demand forecasts.

3 Hidden ERP traps
12 Business Central tables unified
95% Less manual data cleanup

Paradox 1: The Ghost in the Warehouse

If you only forecast what you shipped, you will only ever stock what you already had.

A common shortcut is to pull data straight from Item Ledger Entries. It feels safe because it shows verified, posted inventory. The catch is that the item ledger only records what left the warehouse, not what customers asked for.

The Trap

Looking Only at Shipped Items

A school orders 100 student desks in August, but the warehouse has only 20 in stock, so only 20 ship. The ledger records 20 units. The model learns that August demand was 20, the buying team orders 20 next year, and you run out of stock again.

The Fix

Reading True Demand from Sales Lines

Sales lines hold both Quantity (what was ordered) and Quantity Shipped. Using both, the model learns that real demand was 100 and flags the 80 units lost to a stockout.

Good to Know

Business Central deletes a sales order and its lines once it is fully shipped and invoiced. To keep the original ordered quantity for completed orders, switch on Archive Orders in Sales & Receivables Setup and read from the sales order archive as well as open sales lines.

Simple Rule

When an item runs out of stock, sales drop to zero, but customer demand does not disappear. Always look at ordered quantities, not just shipments.

Paradox 2: The Negative Demand Paradox

A customer returns 30 desks in October from an August order. Did October really have negative demand?

Forecasting models expect demand to be zero or positive. In Business Central, a return is posted as a credit memo in the month it is processed, and it reduces the sales quantity for that month.

This is what happens during the busy school purchasing season:

August Purchase

Initial Order

A school district buys 100 chairs for the new school year. All 100 are delivered.

Demand: +100 units
October Return

Credit Memo

The school ordered too many and returns 30 chairs. A credit memo is posted in October.

ERP shows: −30 units
Model Confusion

Pattern Ruined

The model sees October demand below zero, and August looks higher than it really ended up.

False seasonal signal

To fix this, we handle returns in a separate cleanup step. Instead of subtracting them from October sales, each return is either linked back to its original August order or tracked as a return rate, so the seasonal demand pattern stays clean.

Paradox 3: The Missing Days Dilemma

What does a day with no sales look like in a database? It does not exist.

Business Central only saves a row when something is sold. Classroom furniture at a regional warehouse, such as US-MAIN or US-EAST, might sell on Monday and Thursday with no orders on Tuesday or Wednesday.

Date ERP Table Has Model Sees What Really Happened
Monday 40 units sold Valid row Real sales day
Tuesday No record Missing data point Zero sales, item available
Wednesday No record Missing data point Zero sales, item available
Thursday 15 units sold Valid row Real sales day

A model fed raw data with missing dates cannot calculate rolling averages or trends properly. It jumps straight from Monday to Thursday.

The Calendar Spine

We build a full calendar for every active item and warehouse combination. If there were no orders on Tuesday, the pipeline records an explicit 0 instead of leaving a gap.

How We Solved It in PySpark

This is the core logic we used in Azure Databricks to handle unfulfilled demand and missing days in one transformation:

from pyspark.sql import functions as F


def build_clean_demand_mart(sales_lines_df, active_skus_df, calendar_df):
    # 1. Capture what customers ordered, not just what shipped
    clean_sales = (
        sales_lines_df.select(
            F.col("item_no"),
            F.col("location_code"),
            F.col("order_date").cast("date").alias("calendar_date"),
            F.col("quantity").cast("double").alias("requested_qty"),
            F.col("quantity_shipped").cast("double").alias("shipped_qty"),
        )
        .groupBy("item_no", "location_code", "calendar_date")
        .agg(
            F.sum("requested_qty").alias("daily_requested_demand"),
            F.sum("shipped_qty").alias("daily_shipped_demand"),
        )
    )

    # 2. Build a complete date spine for every active item and warehouse
    sku_date_spine = active_skus_df.crossJoin(calendar_df)

    # 3. Join orders to the spine and fill quiet days with 0
    final_mart = (
        sku_date_spine.join(
            clean_sales,
            on=["item_no", "location_code", "calendar_date"],
            how="left",
        )
        .select(
            F.col("item_no"),
            F.col("location_code"),
            F.col("calendar_date"),
            F.coalesce(F.col("daily_requested_demand"), F.lit(0.0)).alias("demand_qty"),
            F.coalesce(F.col("daily_shipped_demand"), F.lit(0.0)).alias("shipped_qty"),
            F.col("daily_requested_demand").isNull().alias("is_zero_sales_day"),
        )
    )

    return final_mart

active_skus_df holds one row per active item and location, and calendar_df holds one row per date in the forecast window. The cross join creates every item, location and date combination, and the left join keeps days with no orders as explicit zeros.

Real-World Results

Handling these three ERP behaviors made an immediate difference:

Paradox 1 Fixed

No More Stockout Traps

Purchasing teams buy to meet real customer demand instead of repeating past stockouts.

Orders match real demand
Paradox 2 Fixed

Honest Seasons

Autumn returns no longer drag down forecasts, so school-year cycles stay accurate.

Clean seasonal trends
Paradox 3 Fixed

Smooth Timelines

Explicit zero days let the models calculate reliable moving averages.

No more data gaps

What This Means for Data Teams

If you are preparing Business Central data for analytics or machine learning, keep these three points in mind:

  1. Look at what customers ordered. Use sales lines and archived orders to capture real demand, rather than relying only on item ledger entries.
  2. Separate returns from sales. Credit memos belong in return tracking, not mixed directly into sales demand.
  3. Fill in the quiet days. A missing row in an ERP table does not mean missing data. Build a calendar spine so the model sees real zero days.
Key Takeaway

Forecast accuracy starts with the data, not the model. Fix what customers wanted, what came back, and what never got recorded, and the algorithm has something honest to learn from.

Frequently Asked Questions

Why not forecast directly from Item Ledger Entries?

Item ledger entries record what physically left the warehouse. When an item is out of stock, the ledger shows what shipped, not what was ordered, so the forecast learns to repeat past stockouts. Ordered quantities from sales lines show the real demand.

Where does the ordered quantity come from once an order is fully posted?

Business Central deletes a sales order and its lines after it is fully shipped and invoiced. With Archive Orders switched on in Sales & Receivables Setup, an archived copy is kept, so the pipeline reads open sales lines and the sales order archive together.

How should returns be handled in a demand forecast?

Keep them out of the month they were processed. Either link each return back to the original order so the net demand sits in the right month, or track returns separately as a return rate. Both approaches keep seasonal patterns clean.

Is a day with zero sales always a day with zero demand?

Not always. If the item was out of stock that day, zero sales may hide real demand. Flag stockout days using inventory data so the model can tell a quiet day from a day when customers could not buy.

Does this approach only work on Azure Databricks?

No. The same logic works in any Spark environment, including Microsoft Fabric notebooks. The key steps are the same: read ordered quantities, separate returns, and build a calendar spine.

Data and AI Solutions
Working on demand forecasting with Business Central?

CloudFronts helps distributors and manufacturers build clean, reliable data pipelines on Azure Databricks and Microsoft Fabric, turning complex ERP tables into dependable forecast models. To discuss your data, reach out to us.

Contact us at transform@cloudfronts.com

About the Author

Ritika Bobhate

Trainee Consultant · CloudFronts

Ritika is a Trainee Consultant working with Dynamics 365 Business Central and cloud data systems. Her work centers on turning complex ERP tables into clean, trustworthy data pipelines on Azure Databricks and Microsoft Fabric for demand forecasting and operational reporting.

LinkedIn: Ritika Bobhate


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Categories

Secured By miniOrange