Skip to main content
This page guides you through a full example of an Analytical Financial report in XML. The template breaks down account-level activity, applies custom logic (like discounts), and includes clear summaries to support analysis and auditing. What this report shows:
  • Organization and Ledger details.
  • Account-level overview: balance, currency, and alias.
  • Operation breakdowns: original amount, discount, final amount, status, description, and type.
  • Summaries per account: total operations, total value, and average per operation.

Template code


Code breakdown


Organization and Ledger information

<Organization>{{ midaz_onboarding.organization.legal_name }} - CNPJ: {{ midaz_onboarding.organization.legal_document }}</Organization> Displays the organization’s legal name and corresponding CNPJ (Brazilian Tax ID).
  • {{ midaz_onboarding.organization.legal_name }}: retrieves the organization’s name.
  • {{ midaz_onboarding.legal_document }}: retrieves the CNPJ.
<GenerationDate>{% date_time "dd/MM/YYYY HH:mm" %}</GenerationDate> This function applies the date and time when the template is rendered, using the dd/MM/YYYY HH:mm format. {%- with ledger = midaz_onboarding.ledger[0] %} Creates a temporary variable pointing to the first available ledger. This keeps the code cleaner and avoids repetitive references.
  • -: removes extra spaces in the rendered file.
  • ledger: the name of the temporary variable.
  • midaz_onboarding.ledger[0].name: points to the first available ledger.

Looping through accounts

{%- for account in midaz_onboarding.account %}{% endfor %} Loops through all accounts linked to the user. Since most users have more than one account, this allows you to display individual data for each one.
  • midaz_onboarding.account: the full list of user accounts.
  • {%- for account in midaz_onboarding.account %}: the loop runs once per account.
{%- with balance = filter(midaz_transaction.balance, "account_id", account.id)[0] %} Defines a variable named balance that holds the current account’s balance.
  • filter(): scans through midaz_transaction.balance to find the one matching the account.id.
  • [0]: grabs the first match.
  • The result is stored in balance.
<CurrentBalance> {{ balance.available }}</CurrentBalance> Shows the account’s available balance (balance.available).

Looping without {%with...%}

{%- for balance in midaz_transaction.balance %} Loops through all balances to find the one that matches the current account. This is a more explicit alternative to filter().
  • midaz_transaction.balance: The list of all balances.
  • {%- balance in midaz_transaction.balance %}: the loop runs once per balance.
{% if balance.account_id == account.id %} Filters balances to show only those that match the current account being processed.
  • If they match, the balance is displayed.

Currency information

Shows the account’s currency (e.g., BRL, USD) to help you understand the value context.
  • account.asset_code: dynamically injects the currency code.

Grouping operations

<Operations>...</Operations>

Defines the section where all operations for an account are listed.
  • Keeps the report structured and easy to scan.
{%- for operation in midaz_transaction.operation %} Loops through all operations in the transaction, and displays operations that match the current account.
  • operation: represents the current operation that is part of the current transaction.
  • midaz_transaction.operation: the list of all operations in the transaction.
{%- if operation.account_id == account.id %} Ensures that only the relevant operations for the current account are included.
  • If the account_id of the operation is equal to the current account.id, the rest of the block will be executed.
{%- set original_amount = operation.amount %} Defines the original amount and sets it as a variable.
  • original_amount: the name of the variable.
{%- set discount_amount = original_amount * 0.03 %} Defines a variable and calculates a 3% discount on the original amount.
  • discount_amount: the name of the variable.
  • original_amount * 0.03: applies a 3% discount on the original amount.
{%- set final_amount = original_amount - discount_amount %} Subtracts the discount from the original amount to get the final value.
  • final_amount: variable that represents the final value.
  • original_amount - discount_amount: the subtraction operation.

Operation block

Each <Operation> contains detailed information about the transaction. These fields help users audit and understand what happened. <OperationID>{{ operation.id }}</OperationID> Unique ID of the operation. <Description>{{ operation.description }}</Description> Short description of the operation. <Type>{{ operation.type }}</Type> Operation type (e.g., credit, debit, adjustment). <Route>{{ operation.route }}</Route> Associated operation route entry. <OriginalAmount>{{ original_amount }}</OriginalAmount> Original amount before any adjustments. <DiscountAmount>{{ discount_amount }}</DiscountAmount> Value of the discount applied. <FinalAmountWithDiscount>{{ final_amount }}</FinalAmountWithDiscount> Final amount after discount. <Currency>{{ operation.asset_code }}</Currency> The currency used for the operation. <Status>{{ operation.status }}</Status> Operation status (e.g., Approved, pending).

Account summary block

{% count_by midaz_transaction.operation if account_id == account.id %} Counts the number of operations associated with your account and assists in understanding the transaction volume for the reporting period.
  • The count_by function goes through midaz_transaction.operation and adds up how many operations have the same account_id as the current account.
{% sum_by midaz_transaction.operation by "amount" if account_id == account.id %} Sums up the total value of all operations for this account, and outputs the result using two decimal places.
  • sum_by loops through transactions filtered by account_id.
  • Sums the amount fields.
{% avg_by midaz_transaction.operation by "amount" if account_id == account.id %} Calculates the average operation value for this account. Useful for spotting spending patterns or outliers.
  • avg_by applies the average calculation to the amount values.
  • Only considers operations for the current account.

Template output