Blog · 19 November 2026 · Paulo Cordeiro

Customer master data cleansing in Brazil: groups and hierarchy

How to decide what is the same customer in Brazil: CNPJ root, branches, corporate group and ship-to sites. What to merge, what to link, alphanumeric CNPJ.

In customer master data cleansing for a Brazilian B2B base, "the same customer" is decided in layers: the CNPJ root identifies the company, the full CNPJ identifies each establishment, and the corporate group is your own internal definition. Only true duplicates are merged (the same full CNPJ or the same CPF registered twice). Branches, group companies and ship-to locations are linked in a hierarchy, never collapsed into one record.

Some context for readers outside Brazil: the CNPJ is the Brazilian corporate taxpayer ID, issued by the Receita Federal (Brazil's federal revenue service), and the CPF is the individual taxpayer ID. The rules below apply to Brazil.

The scene is familiar. Sales asks for "a single view of the customer", someone filters the base by trade name and gets 14 records. Three are the same store registered more than once. Five are branches. Two are companies with a different root that belong to the same owners. The rest are job sites registered as new customers so the invoice would carry the right delivery address.

If the cleanup merges everything into one record, billing starts issuing invoices under the wrong CNPJ. If it merges nothing, credit grants a limit to each branch as if they were independent customers. The job is knowing what to merge, what to link and what never to merge.

What does the official source say about root, establishment and head office?

The CNPJ has 14 positions. According to SERPRO (the Brazilian federal data processing service), the first eight identify the company and form the "root" of the registration, the next four are the order number, which identifies the establishments (the head office or a branch), and the last two are check digits calculated with modulus 11.

The Receita Federal adds two points that affect any deduplication rule, in its questions and answers on the alphanumeric CNPJ (in Portuguese):

  • The 0001 suffix indicates the head office when the CNPJ is generated, but that link is not permanent: a branch can become the head office with a different order number. You cannot infer the head office from 0001 alone.
  • The alphanumeric format applies to new registrations, including new branches of companies already registered in the numeric format. An old company can get a new branch with letters in the order number.

Agência Gov, the Brazilian government news agency, reports that the alphanumeric CNPJ is being implemented from July 31, 2026, according to the Receita Federal; existing CNPJs do not change and both formats coexist.

Corporate group does not appear in these sources as a registration key. For cleansing purposes it is an internal policy definition (credit, sales), backed by evidence. Companies in the same group can have different roots: the root identifies the company, not the group.

This reading is the starting point of customer and supplier master data cleansing for a B2B base.

How do you decide what counts as the same customer?

1. Normalize the key before comparing

Comparing a CNPJ with punctuation, without it, with spaces or with a leading zero dropped by a spreadsheet creates false "new customers". Before any matching:

  • Strip dots, slash, hyphen and spaces.
  • Store the key as a 14 character text value. A CNPJ can have leading zeros, and the alphanumeric one has letters.
  • Accept uppercase letters A to Z. Do not convert the CNPJ to a number and do not strip letters: that erases part of the identifier.
  • Validate the check digits with the Receita Federal rule, which converts each character to its ASCII code minus 48. The same routine works for both formats.

An old rule that accepts digits only will flag a legitimate new branch as invalid. Worse, it may drop the letters and match the record to a different establishment.

2. Merge only true duplicates

A true duplicate is the same full CNPJ (14 positions) in two or more records, or the same CPF in two records. That is the only merge case. A similar name, the same phone number or the same address can raise a flag, but none of them justifies a merge on its own.

Individual customers (CPF holders) fall under their own personal data rules and deserve separate treatment.

3. Link establishments to the company by root

Same root with a different order number means the same company with different establishments. Each establishment has its own CNPJ and address and, where applicable, its own state registration (inscrição estadual), so each keeps its own record. What changes is the link: all of them point to the same company.

Never merge different branches into one record. The invoice, collection and delivery depend on the right establishment.

4. Link companies to the group with evidence

To build the corporate group, use the list of partners and managers (known in Brazil as QSA) from the official CNPJ lookup as evidence, together with the rule agreed by credit and sales. The same lookup shows the registration status of each CNPJ. Record the lookup date: partners change.

5. Treat addresses and roles as customer attributes

Ship-to location, bill-to address and payer are roles of the customer. If the place has its own CNPJ, it is an establishment (step 3). If not, it is a location linked to the establishment that buys, not a new customer.

6. Build the tree and define who decides

The hierarchy looks like this:

  • Corporate group (internal definition)
    • Company (CNPJ root)
      • Establishment (full CNPJ: head office or branch)
        • Ship-to locations, bill-to address, payer

Credit and sales decide the group, because the rule affects limits and negotiation. The master data team decides duplicates, because that rule is about the key. Mixing the two roles tends to stall the project in debates with no owner.

7. Merge records with history without deleting

When both duplicate records have orders, invoices or open receivables, the merge needs three things:

  • A survivorship rule: which record stays and which source wins for each field (data checked in the official lookup beats typed data).
  • A cross-reference map: old code to surviving code, for reports, integrations and reconciliation.
  • A block on the duplicate for new orders instead of deletion. The history stays available.

For the Business Partner context in SAP S/4HANA, see the post on Business Partner master data in S/4HANA.

When should you merge, link or block a record?

Situation foundHow to identify itWhat to doBatch or decision (whose)
Same full CNPJ in two recordsIdentical normalized 14 character keyMerge with survivorship rule, cross-reference map and block on the duplicateBatch; master data review when there is history
Same CPF in two recordsIdentical normalized CPFMerge, with the same care for historyBatch; master data review
CNPJ that fails to match because of formatPunctuation, spaces, lost leading zero, lowercase letterNormalize the key and validate check digits accepting lettersBatch
Head office and branches unlinkedSame root (first 8 positions), different order numberKeep separate and link to the same companyBatch
Different branches in a single recordOne record with addresses from more than one establishment, or the address of another establishment with the same rootSplit into one record per establishmentMaster data decision
Companies with different roots and the same ownersShared partners in the QSALink to the corporate group according to policyCredit and sales decision
Ship-to location registered as a customerRecord with no CNPJ of its own and a job site or warehouse addressConvert into a ship-to location linked to the establishmentMaster data decision with sales
Payer is a different CNPJReceivables settled by an establishment other than the buyerRecord the payer role without merging recordsCredit and collections decision
Registration status not activeOfficial CNPJ lookupBlock according to internal policy; do not deleteCredit and master data decision

What does a hypothetical case with seven records look like?

Hypothetical example. Names and CNPJs are fictitious and invalid.

Before:

  • C-101 Alfa Distribution, 00.000.000/0001-00
  • C-245 ALFA DISTRIBUTION LTD, 00000000000100 (same CNPJ, no punctuation)
  • C-310 Alfa Distribution Campinas, 00.000.000/0002-00
  • C-512 Alfa New Branch, 00.000.000/00A1-00 (new branch with a letter; the old rule flagged it as invalid because of the letter in the order number)
  • C-618 Alfa Logistics, 00.000.001/0001-00 (different root, same partners in the QSA)
  • C-702 Alfa Highway Job Site, no CNPJ of its own, construction site address
  • C-733 Alfa South Warehouse, same full CNPJ as the head office (C-101) with a warehouse address

After:

  • C-101, C-245 and C-733 merged: they are true duplicates (same full CNPJ). C-101 survives, C-245 and C-733 are blocked, with cross-reference entries and history preserved. The warehouse address from C-733 becomes a ship-to location of C-101.
  • C-310 and C-512 remain separate establishments, linked to the company with root 00.000.000.
  • C-618 remains a separate company, linked to the "Alfa" group by a credit decision, with the QSA lookup kept as evidence.
  • C-702 becomes a ship-to location of the buying establishment, and its customer record is blocked.

Result: one group, two companies, four establishments (three under root 00.000.000 and one under root 00.000.001) and two ship-to locations. No record deleted.

Where do you start the cleansing?

  1. Extract the customer base with CNPJ, CPF, address and code, and normalize the key accepting letters.
  2. Run check digit validation for both formats and set invalid keys aside for correction.
  3. Group by full key (merge candidates) and by root (link candidates).
  4. Write the corporate group rule with credit and sales before linking any company.
  5. Check registration status and QSA in the official lookup and record the date.
  6. Run merges with survivorship, cross-reference and blocking, starting with records that have no history.
  7. Apply the same rule at data entry so duplicates do not come back. The post on customer onboarding approval shows that control in the approval flow, and the guide on measuring master data quality helps track the result.

Frequently asked questions

Does the same CNPJ root mean the same customer?

It means the same company, not the same establishment. The head office and branches share the root, and each has its own full CNPJ and address and, where applicable, its own state registration (inscrição estadual). They stay in separate records, linked to the same company.

Can I merge all branches into a single customer record?

No. Each establishment has its own CNPJ and address and, where applicable, its own state registration (inscrição estadual), and the invoice, collection and delivery depend on them. The single view comes from the hierarchy, not from merging.

Does the alphanumeric CNPJ change deduplication of existing customers?

Existing CNPJs do not change. But an existing company can get a new branch with letters in the order number, and a new root can be alphanumeric. Matching rules must accept uppercase letters and validate check digits using the ASCII minus 48 conversion, without turning the CNPJ into a number.

How do you prove two companies belong to the same corporate group?

The root does not prove it, because companies in the same group can have different roots. Use the QSA from the official CNPJ lookup as evidence and apply the group definition approved by credit and sales, recording the lookup date.

What do you do with a duplicate record that has open receivables?

Merge it with a survivorship rule and a cross-reference map, then block the duplicate for new orders. Do not delete it: the order and receivables history must remain available for queries and reconciliation.

Is a ship-to location a new customer?

If the place has no CNPJ of its own, no. It is an address linked to the buying establishment. If it has its own CNPJ, it is an establishment and enters the hierarchy with its own record. For how the customer address matters under Brazil's tax reform, see the post on customer master data and the Brazilian tax reform.

How 4MDG can help

4MDG runs customer and supplier data cleansing that validates CPF and CNPJ against official sources, finds duplicates by CPF, CNPJ and similarity, and consolidates each group into a golden record, with similarity scoring, survivorship and head office, branches and corporate group linked. The method follows five stages (diagnostic, standardization, deduplication, validation and enrichment, continuous governance). The first step is a free diagnostic on a real sample of your base, with no commitment. If you would rather talk first, use the contact page.

Notice: the passages about the CNPJ are an operational reading of the official sources cited, not legal or tax advice.

Sources

Have a question or want to talk about this?

Talk to a 4MDG specialist — we reply through the channel you prefer.

The international code is added when you save.