> For the complete documentation index, see [llms.txt](https://help.openloyalty.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.openloyalty.io/technical-guide/data-exports/reconciliation.md).

# Reconciliation

How export files connect, which fields to join, and how to reconcile balances and counts.

## Reconciliation: How the Data Connects

Use this reference to combine export files into one data model.

### Load files correctly

* **Delta files:** Upsert by the documented primary key. Keep the newest `updatedAt`.
* **Custom Events:** Upsert by `customEventId`. Keep the latest file version.
* **Snapshots:** Replace the previous state. Do not merge snapshot files.

{% hint style="warning" %}
Campaign Visibility, Members Segments, and Wallet Balance are snapshots. A missing row is no longer in the current state.
{% endhint %}

Start with an `*_all_until_YYYY_MM_DD.csv` export, if available. Then load daily deltas in date order. Load reference data before event-style files.

### Shared identifiers

| Concept     | Canonical source               | Referencing columns                                      |
| ----------- | ------------------------------ | -------------------------------------------------------- |
| Tenant      | Tenants → `tenantId`           | `tenantId`, `storeId`, `storeCode`                       |
| Member      | Members → `memberId`           | `memberId`, `customerId`, `targetId`, `referrerMemberId` |
| Wallet      | Wallet Balance → `walletId`    | `walletId`, `defaultAccount.accountId`                   |
| Tier        | Tiers → `levelId`              | `levelId`, `currentTierId`, `manuallyAssignedLevelId`    |
| Campaign    | Campaigns → `campaignId`       | `campaignId`, `visibleCampaigns[]`                       |
| Transaction | Transactions → `transactionId` | `transactionId`                                          |
| Reward      | Rewards → `rewardId`           | `rewardId`, `reward.rewardId`                            |
| Segment     | Segments → `segmentId`         | `segmentIds[]`, `segments[]`                             |

All identifiers are UUIDs. They are unique across the environment.

### Direct joins

* Join **Campaign Calculated Effect Results** to **Campaign Execution** with `campaignExecutionId`.
* Join **Unit Transfers** to Transactions, Campaigns, and Custom Events with their IDs.
* Join **Rewards Redemption** to Rewards through `reward.rewardId`.
* Unnest `segmentIds` and `visibleCampaigns` before joining them.
* Join **Achievement Usage** to Achievements with `achievementId`.

### Reconcile wallet balances

For a wallet balance dated **D**, use transfers created before `D+1 00:00 UTC`.

* Add `adding` and `p2p_adding` transfers.
* Subtract `spending`, `p2p_spending`, `blocked`, and `expired` transfers.
* Exclude cancelled transfers.
* Exclude pending `adding` transfers from `activeUnits`.

{% hint style="warning" %}
`points` is always positive. Apply the sign from `type` before aggregating.
{% endhint %}

The following identity normally holds:

```
activeUnits = earnedUnits + transferredUnits − spentUnits − blockedUnits − expiredUnits
```

Prefer [Wallet Balance](/technical-guide/data-exports/data-structure-and-types/wallet-balance.md) over `members.defaultAccount`. Member profile balances can be stale.

### Known limitations

No exported ID directly links an issued reward to its spending transfer. No ID directly links an effect result to its resulting transfer or issued reward. Match these records using member, campaign, amount, wallet type, and close timestamps.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.openloyalty.io/technical-guide/data-exports/reconciliation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
