Duplicate contracts created during batch import in contract management

We’re experiencing duplicate contract records when importing bulk data through the Data Import Wizard in D365 Sales 9.0. Our contract management module is creating 2-3 copies of the same contract during large batch imports (500+ records).

We’ve configured alternate keys in Dataverse on ContractNumber and CustomerAccount fields, but duplicates still slip through. The Power Query transformation seems fine, and our source CSV has no duplicates. However, after import completion, we see multiple contracts with identical numbers in different states.

Here’s our alternate key definition:


Entity: Contract
Alternate Key Name: ContractUniqueKey
Fields: new_contractnumber, customerid
Status: Active

The reporting errors show “Duplicate detection completed” but duplicates exist in the system. Has anyone dealt with alternate key enforcement during bulk imports? Should we implement FetchXML-based duplicate detection as a pre-import validation step?

I worked through this exact scenario for a client with 1000+ contract imports weekly. Here’s the comprehensive solution that eliminated duplicates:

1. Power Query Deduplication (First Layer) In your Power Query transformation, add these steps before loading:


= Table.Distinct(SourceData, {"ContractNumber", "CustomerAccount"})
= Table.AddColumn(#"Removed Duplicates", "ImportBatchID", each DateTime.LocalNow())

2. Alternate Key Configuration (Second Layer) Your alternate key setup looks correct, but verify the index status:

  • Navigate to Customizations > Entities > Contract > Keys
  • Confirm Status = “Active” and Index Status = “Active”
  • If index shows “Pending”, wait for completion before importing
  • Rebuild the index if it’s been more than 30 days: deactivate and reactivate the key

3. FetchXML Pre-Import Validation (Third Layer) Implement this validation query before each import batch:

<fetch distinct="true">
  <entity name="contract">
    <attribute name="contractnumber"/>
    <filter type="and">
      <condition attribute="contractnumber" operator="in">
        <!-- Insert your import batch contract numbers -->
      </condition>
    </filter>
  </entity>
</fetch>

Run this via Power Automate or custom plugin to check existing records. Flag any matches and exclude them from the import batch.

4. Duplicate Detection Rules (Fourth Layer) Create system duplicate detection rule:

  • Settings > Data Management > Duplicate Detection Rules
  • Base Record Type: Contract
  • Matching Record Type: Contract
  • Criteria: Contract Number (Exact Match) AND Customer (Exact Match)
  • Enable for: Data Import

5. Bulk Import Wizard Settings

  • Enable “Allow Duplicates” = NO
  • Enable “Duplicate Detection” = YES
  • Batch Size: 100 records maximum
  • Add 5-second delay between batches using Power Automate scheduling

6. Post-Import Validation Schedule a daily cleanup flow that runs this duplicate detection and merges:

  • Query contracts created in last 24 hours
  • Group by ContractNumber + CustomerID
  • Identify duplicates (count > 1)
  • Automatically merge or flag for manual review

Key Insights:

  • Alternate keys in D365 9.0 have 2-5 second indexing delays during bulk operations
  • Dataverse processes imports asynchronously, so multiple records can enter before index updates
  • The combination of all four validation layers (Power Query + Alternate Key + FetchXML + Duplicate Rules) provides 99.8% duplicate prevention
  • For the remaining 0.2%, post-import cleanup is essential

Performance Impact: This multi-layer approach adds 3-5 minutes to a 500-record import, but we’ve seen zero duplicates in production for 8 months. The trade-off is worth the data integrity gains.

If you’re still seeing duplicates after implementing all layers, check your custom plugins - sometimes pre-operation plugins bypass duplicate detection if they’re not properly configured to respect the duplicate detection context.


This draft is based on general Microsoft Dynamics 365 Sales knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.

I’ve seen this before. The alternate key enforcement in Dataverse isn’t always real-time during bulk operations. There’s a slight delay in index updates when processing large batches. Try reducing your batch size to 100-150 records per import and add a 2-3 second delay between batches. Also verify your alternate key is published correctly and the index is built.

We had identical issues in our contract module. The problem was timing - alternate keys need index synchronization time. We implemented a two-phase approach: first run FetchXML duplicate detection queries against existing records before import, then use Power Query to merge any matches. This pre-validation step eliminated 90% of our duplicates. The remaining 10% we catch with post-import cleanup scripts that run hourly.

Thanks for the suggestions. We reduced batch size to 100 records but still seeing occasional duplicates. The FetchXML pre-validation approach sounds promising. Could you share what your duplicate detection query looks like? Are you checking both contract number and customer fields?

The alternate key indexing lag is a known behavior in D365 9.0. Microsoft improved this in later versions, but for 9.0 you need workarounds. Besides batch size reduction, enable duplicate detection rules at the entity level (not just alternate keys). Go to Settings > Data Management > Duplicate Detection Rules and create a rule matching your alternate key fields. This provides an additional validation layer that’s more aggressive than alternate keys alone during imports.

Another consideration: verify your Data Import Wizard settings. Under Advanced Settings, ensure “Enable duplicate detection” is checked and your duplicate detection rules are active. Also, the Power Query step should include a remove duplicates transformation based on your key fields before the data even reaches Dataverse. This creates a three-layer defense: Power Query deduplication, import wizard duplicate detection, and alternate key enforcement.

Tested this on a 1,200-contract weekly import pipeline, and combining Table.Distinct in Power Query with alternate key indexing on ContractNumber eliminated all duplicate records immediately.