Monday, November 17, 2025

Archiving D365 F&O Data with Dataverse Long Term Retention

Dynamics 365 Finance & Operations now offers a robust archiving capability that moves historical, inactive data out of live tables while keeping it accessible for audits and analytics.

Here’s what you’ll find in this guide:

  • How the archiving process works
  • Which data types are supported today
  • How to safely include your custom fields and tables

If you’re still deciding whether archiving is the right next step, start with our blog:
D365 F&O Database Optimization
It covers practical clean-up techniques and explains how they fit into a broader data lifecycle strategy perfect context before diving into Dataverse-based retention.

Why Archive?

  • Performance: Reduce row counts in large tables to speed up queries and batch processing.
  • Cost & Operations: Smaller databases mean lower capacity usage, faster backups/restores, and smoother refreshes and upgrades.
  • Compliance: Retain historical data securely for audits and regulatory requirements without bloating your live system.

  The Archiving Lifecycle in D365 F&O

  1. Criteria & Marking – Choose the functional scenario and define archival rules (e.g., completed or closed status older than X months).
  2. Replication to Dataverse – Copy data from live tables to long-term storage managed via Dataverse.
  3. Reconciliation – Verify that all marked rows are present in long-term retention.
  4. Move & Delete – Transfer validated rows to history tables and remove them from live tables to reduce operational size.
  5. Access & Restore – Use dedicated inquiry pages to view history, restore data if needed, or purge when permitted.

 

What Can You Archive Today?

Initial support focuses on high-volume areas for maximum impact:

  • Finance: General ledger, tax transactions
  • Supply Chain: Inventory transactions, inventory journals, sales orders

Microsoft plans to add more scenarios in future releases (e.g., Commerce, Customer Invoice Data).


Working with Archived Data

  • Read Access: History data remains queryable in F&O via dedicated inquiry pages.
  • Analytics: Archived data in Dataverse can be accessed through Fabric or Synapse for reporting.
  • Deletion: When retention periods expire, purge data from long-term storage according to policy.

 

Including Custom Tables and Fields – Must-Do Steps

Most real-world implementations include extensions, and the archiving framework supports them. However, you need to make sure your schemas are aligned for a smooth process:

1. Mirror Custom Fields in the History Table

The history table should include all columns from the live table.
Exceptions: Platform-managed columns like SysRowVersion and SysDataState don’t need to be duplicated.

2. Add Custom Fields to the BI (Virtual) Entity

Dataverse long-term retention relies on virtual/BI entities to interact with F&O data.

  • Add your custom fields to the relevant BI entity.
  • Refresh the entity in Dataverse so the archiving process recognizes them.
  • Important: Do not add relationships between BI entities.

If you’ve extended created/modified fields, follow the recommended naming conventions in the BI entity.

 

Table field

Bi Entity

CreatedDateTime

CreatedOn

ModifiedDateTime

SysModifiedDateTime

CreatedBy

SysCreatedBy

ModifiedBy

SysModifiedBy

 

Validation Tip

Before going live, run schema comparison queries:

  • Compare live vs. history tables
  • Compare history vs. BI entity

This helps catch missing columns early and prevents archival job failures or reconciliation mismatches.
Use the provided scripts to validate whether fields match the expected schema.

Table vs History table:

DECLARE @tmpDataTable Table (SrNo int, Scenario VarChar(10), LiveTable varchar(100), HistoryTable varchar(100), BiEntity varchar(100))

INSERT INTO @tmpDataTable values(1,'GL','GENERALJOURNALACCOUNTENTRY','GENERALJOURNALACCOUNTENTRYHISTORY','GeneraljournalaccountentryBiEntity')

select * from @tmpDataTable

--SELECT QUERY TO IDENTIFY SCHEMA MISMATCH

 SELECT T.SrNo,T.Scenario, L.COLUMN_NAME,L.TABLE_NAME,HistoryTable,BiEntity--, *

FROM @tmpDataTable T JOIN INFORMATION_SCHEMA.COLUMNS L ON T.LiveTable = L.TABLE_NAME               LEFT OUTER JOIN INFORMATION_SCHEMA.COLUMNS H ON L.COLUMN_NAME = H.COLUMN_NAME AND  T.HistoryTable= H.TABLE_NAME

WHERE --L.TABLE_NAME IN (N'SALESTABLE') AND

H.COLUMN_NAME IS NULL AND  L.COLUMN_NAME not in ('SYSDATASTATECODE','SYSROWVERSION') Order by T.SrNo

History table Vs Bi Entity:

DECLARE  @tmpDataTable Table (SrNo int, Scenario VarChar(10), LiveTable varchar(100), HistoryTable varchar(100), BiEntity varchar(100))

INSERT INTO @tmpDataTable values(1,'GL','GENERALJOURNALACCOUNTENTRY','GENERALJOURNALACCOUNTENTRYHISTORY','GeneraljournalaccountentryBiEntity')

 SELECT T.SrNo,T.Scenario, L.COLUMN_NAME,L.TABLE_NAME,HistoryTable,BiEntity--, *

FROM @tmpDataTable T JOIN INFORMATION_SCHEMA.COLUMNS L ON T.LiveTable = L.TABLE_NAME  LEFT OUTER JOIN INFORMATION_SCHEMA.COLUMNS H ON L.COLUMN_NAME = H.COLUMN_NAME AND  T.BiEntity = H.TABLE_NAME

WHERE --L.TABLE_NAME IN (N'SALESTABLE') AND H.COLUMN_NAME IS NULL

AND  L.COLUMN_NAME not in ('SYSDATASTATECODE','SYSROWVERSION')

Order by T.SrNo, L.TABLE_NAME, L.COLUMN_NAME

 

3. Adding New Tables to an Archive Scenario

If you need to include custom tables in an archive scenario, you can extend the existing setup. These tables should relate either directly or indirectly to the main live table.

What to do:

  • Create a corresponding history table and BI entity that mirrors the structure of the live table.
  • You generally don’t need to replicate indexes; a clustered index on RecId is usually sufficient for history tables.
  • Extend the ArchiveAutomationJobRequestCreator class for a scenario to add the new table to archive table chart

Operational Guardrails & Best Practices

  • Start in a sandbox: Validate the full archive flow end-to-end (criteria → replicate → reconcile → move/delete → inquiry/restore).
  • Align with retention policies: Work with compliance and legal teams to define time-based and event-based rules.
  • Build safeguards: Use role-based access, approvals, and backout plans for initial runs.
Maximize savings

a. Bring Your Own Lake (BYOL): Use a custom data lake to reduce storage costs. Note: Delete actions in F&O won’t remove data from the lake; instead, the SysDataStateCode flag will be set to 1(1-archived, 0- Live). 



b. Purge aggressively: Remove data from history tables and Dataverse using bulk delete APIs for maximum cost savings.


Putting It All Together – Sample Rollout Plan

  1. Pilot scope: Archive sales orders older than 24 months that are fully invoiced and closed.
  2. Extend schema: Add custom fields to SalesTableHistory and the corresponding BI entity; refresh in Dataverse.
  3. Dry run in sandbox: Validate replication, reconciliation, and accessibility via inquiry pages.
  4. Cutover window: Execute in production during a planned maintenance window; monitor database size and job telemetry.
  5. Analytics check: Ensure your Fabric/Synapse model includes both live and historical layers for complete reporting.

Resources

 

D365 F&O Database Optimization

As your business expands, so does the Dynamics 365 Finance & Operations database. This growth can affect performance, increase maintenance windows, and drive up storage costs. To keep things sustainable, here’s a practical approach to reducing database size: (1) Start with Quick Wins – Cleanup Routines, (2)Archive Historical and Inactive Data, (3) Offload Analytics – Use Fabric or Synapse Link, and (4) Sandbox Optimization Strategies

Step 1: Start with Quick Wins – Cleanup Routines

Begin by tidying up the data you don’t need every day. Categorize your data based on importance and compliance requirements. Archive anything you need to keep for regulatory reasons, and safely delete less critical items.

Microsoft offers several built-in cleanup routines that help reduce database size and improve performance. These routines cover different modules and system administration areas and should be scheduled regularly as part of your data hygiene plan.

Why bother?
Removing old logs, history, and staging tables can make queries faster and backups leaner with minimal risk if tested properly.

Examples of common cleanup routines:

  • Batch job history cleanup
  • Database log cleanup
  • Notification cleanup
  • DMF staging and execution history cleanup

You’ll find these under System Administration > Periodic Tasks or within modules like Inventory Management, Sales, Procurement, and Production Control. If the standard jobs don’t meet your needs, you can deploy custom scripts.

Best practice tips:

  • Always check the business impact before running a cleanup.
  • Test in a sandbox environment first.
  • Schedule jobs outside business hours to avoid disruption.

For more details, see https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/sysadmin/cleanuproutines.

Step 2: Make It Durable – Archive Historical and Inactive Data

Cleanup routines are great for regular maintenance, but archiving is your long-term strategy for improving performance, meeting compliance requirements, and cutting storage costs.

How Archiving Works in Dynamics 365 F&O

Here’s the high-level process:

  1. Define your criteria – Identify which records in your live tables are ready for archiving.
  2. Replicate to Dataverse – Move those records into long-term retention.
  3. Reconcile – Confirm that all marked records exist in Dataverse.
  4. Move and delete – Shift data to history tables and remove it from live tables to shrink your operational database.
  5. Access when needed – Use dedicated inquiry pages to view archived data, restore it to live tables, or purge it when appropriate.

What You Can Archive Today

  • Finance: General ledger, tax transactions
  • Supply Chain: Inventory transactions, inventory journals, sales orders
    (More data types are planned in future releases.)

Why It Matters

Archiving reduces the size of your operational database, which means:

  • Faster performance on large tables
  • Easier backups, refreshes, and upgrades
  • Lower capacity costs

Customization Tips

If you have custom fields or tables:

  • Mirror them in the corresponding history tables and BI entities.
  • Refresh the virtual entity in Dataverse so those fields are included in long-term retention.
  • Avoid adding relationships to BI entities; keep the history table schema aligned with the live table (except for platform-managed fields like SysRowVersion and SysDataState).

 

Step 3: Offload Analytics – Use Fabric or Synapse Link

When you need deep analytical reporting or large-scale historical insights, avoid querying the transactional database directly. Instead, offload data from Dynamics 365 Finance & Operations to a Lakehouse using Microsoft Fabric or Synapse Link.
This approach ensures:

  • Faster performance for operational workloads
  • Scalable analytics without impacting day-to-day transactions

 

Step 4: Optimize Your Sandboxes

Data Cleansing

  • Remove older transactional records that are no longer needed.
  • Use Microsoft’s standard cleanup routines wherever possible.
  • If standard routines don’t cover your needs, create custom scripts.

Pro Tip: For bulk deletions, use SQL queries. Deleting directly from F&O can be slow and resource intensive.

Sandbox Review

  • Audit active projects and check how sandboxes are being used.
  • Reduce the number of sandboxes if they’re underutilized to cut costs and free up resources.

Step 5: Governance – Monitor and Iterate

Good governance keeps everything running smoothly.

  • Use Power Platform Admin Centers and capacity views to monitor storage usage and trends.
  • Set a quarterly review cycle:
    • Validate cleanup results
    • Revisit archive criteria
    • Audit analytics pipelines

 Implementation Checklist

  • Start with low-risk cleanups: Identify candidates, test in a sandbox, and schedule recurring jobs.
  • Define archival criteria: Use factors like age, status, or legal hold. Begin with a pilot scenario (e.g., Sales orders).
  • Handle customizations: Include custom fields and tables in history tables and BI entities, then refresh in Dataverse.
  • Shift analytics: Move reporting to Synapse Link or Fabric, catalogue your “gold” datasets, and retire direct reporting on live tables.

Key Takeaways

  • Begin with cleanup routines for quick wins.
  • Move to archiving for a sustainable way to shrink your production database.

If you’re ready to explore advanced strategies for long-term retention and archiving, check out our companion post: Archiving D365 F&O Data with Dataverse Long-Term Retention”

In that article, we dive into:

  • How Dataverse supports compliance and scalability
  • Advanced approaches for archiving beyond basic clean-up
  • Leveraging Dataverse for analytics and long-term data management