CASE : access multiple transaction values from each company in a consolidation file

In this example, we’ll examine a piece of Liquid code that retrieves multiple transaction values for each company within a consolidation file. This approach is particularly useful when you need to access the transaction values for a specific company, such as company X, in your consolidation file.

Below, you can find the code snippet with the logic that is needed to access/ obtain the transaction values from each company in a consolidation file:

{% comment %}get the value_options for the input as: select{% endcomment %}
{% assign consolidation_companies = company.analytical_type_1_codes %}
{% assign consolidation_companies_options = consolidation_companies | map:"reference" | join:"|" %}
{% assign consolidation_companies_codes = consolidation_companies | map:"code" | join:"|" %}

{% input custom.chosen_file.conso as:select options:consolidation_companies_options option_values:consolidation_companies_codes %}
{% assign dimension_code = INT(custom.chosen_file.conso) %}

{% comment %}get the adjustment value per company{% endcomment %}
{% assign adjustments = period.adjustments | analytical_code:dimension_code %}
{% for adj in adjustments %}
  {% comment %}access the transactions drop for each adjustment "adj"{% endcomment %}
  {% assign adj_transactions = adj.transactions %}
  {% for transaction in adj_transactions %}
    {% capture transaction_value_dimension %}transaction_value_dimension_{{ transaction.account.id }}{% endcapture %}
    {% assign [transaction_value_dimension] = [transaction_value_dimension]+transaction.value %}
    ID: {{ transaction.account.id }}
    Name {{ transaction.account.name }}
    Value: {{ [transaction_value_dimension] }}
    Dimension: {{ dimension_code }}
  {% endfor %}
{% endfor %}

**Printing the transaction values outside the for loop by using their unique account ID:**

Aandelen beursgenoteerde effecten: {{ transaction_value_dimension_13997750 }}
Agio reserve: {{ transaction_value_dimension_13997617 }}
Verkrijgingsprijs deelnemingen in groepsmaatschappijen: {{ transaction_value_dimension_13997619 }}

Let’s start with the beginning on how to access data in a consolidation file, where information from multiple company files is merged into a single company file, allowing data to be organized by specific entities:

{{ company.analytical_type_1_codes }}

This returns an array containing all the companies included in the consolidation file, providing details such as:

  • code: a unique identifier for each company
  • reference: the name of each company

More information about analytical/consolidation can be found in one of our other cases here. Or you can also consult our read me page here to read more about this topic.

1) Obtain consolidation company Options and Codes

The first part of the code is responsible for obtaining and formatting the analytical_type_1_codes associated with a company.

{% assign consolidation_companies = company.analytical_type_1_codes %}
{% assign consolidation_companies_options = consolidation_companies | map:"reference" | join:"|" %}
{% assign consolidation_companies_codes = consolidation_companies | map:"code" | join:"|" %}
  • The company.analytical_type_1_codes contains an array of analytical codes related to the company, as already explained before.
  • consolidation_companies_options: by using the map filter, we extract the reference values from each analytical code and join them with a pipe “|”. This provides a formatted string of the references, useful for displaying as options in a selection input.
  • consolidation_companies_codes: similarly here, we use the map filter to extract the code values, joining them with a pipe “|”. This gives us a formatted string of the codes, which can be used for backend processing or validation purposes.

This first section in our code is essential for transforming raw data into a format that can be used for user input and for further processing.

{% input custom.chosen_file.conso as:select options:consolidation_companies_options option_values:consolidation_companies_codes %}
{% assign dimension_code = INT(custom.chosen_file.conso) %}

The database variable custom.chosen_file.conso will contain that unique code of one of the companies in your consolidated file you’ve chosen with the dropdown. Later on in our code, we are using this unique code to access the specific transaction value of a set of accounts.

2) Process adjustments for each company

The second part of the code focuses on iterating over the company’s dimensions, finding the corresponding adjustments for each company, and then calculating the total transaction values per company and account.

{% comment %}get the adjustment value per company{% endcomment %}
{% assign adjustments = period.adjustments | analytical_code:dimension_code %}
{% for adj in adjustments %}
  {% comment %}access the transactions drop for each adjustment "adj"{% endcomment %}
  {% assign adj_transactions = adj.transactions %}
  {% for transaction in adj_transactions %}
    {% capture transaction_value_dimension %}transaction_value_dimension_{{ transaction.account.id }}{% endcapture %}
    {% assign [transaction_value_dimension] = [transaction_value_dimension]+transaction.value %}
    ID: {{ transaction.account.id }}
    Name {{ transaction.account.name }}
    Value: {{ [transaction_value_dimension] }}
    Dimension: {{ dimension_code }}
  {% endfor %}
{% endfor %}

Now let’s split the piece of code into smaller parts, piece by piece:
{% assign adjustments = period.adjustments | analytical_code:dimension_code %}

This assign variable fetches the list of adjustments for the selected dimension_code using the analytical_code filter. To clarify, with dimension_code we are referring to the various companies that are included in your consolidation file.

We then iterate over each adjustment (adj) and accesses the transactions associated with that adjustments.

{% for adj in adjustments %}

As a last step, we iterate over each individual adjustment transaction. Iterating over these adjustments (adj) we access the list of transactions associated with each adjustment, using adj.transactions.

The reason why we are doing this, is because for 1 account, multiple adjustments can be booked in Silverfin. If we don’t iterate over each individual adjustment transaction, we will only be able to capture the last transaction value of an account, if multiple adjustments were booked on that same account.

{% comment %}access the transactions drop for each adjustment "adj.transactions"{% endcomment %} 
{% assign adj_transactions = adj.transactions %}
{% for transaction in adj_transactions %}

Inside the loop for each transaction, we generate a unique identifier for the transaction based on its account.id. This is done using the capture tag, which constructs a dynamic string like transaction_value_dimension_13997750 :

{% capture transaction_value_dimension %}transaction_value_dimension_{{ transaction.account.id }}{% endcapture %}
{% assign [transaction_value_dimension] = [transaction_value_dimension]+transaction.value %}

The transaction’s value is then added to the transaction_value_dimension for that specific account and company. The result of this is that the code accumulates the total transaction values per account for each company and stores them in dynamically named variables. These dynamically named variables can come in handy if you need to print or use the transaction values outside your for loop.