Hi all,
Been working lately on a use case which requires data cleansing for an export:
All external adjustments as a summary in a CSV export - where if there’s multiple adjustments of the same account code it compiles those ones together. Right now I’m trying to get the cleansing right in a Reconciliation where I can see the values and behaviour clearer.
I’ve tried several ways to approach so far…
I tried to do matching the way Silverfin recommends (as per the people example where gender is male or female) but because I need to go from adjustments side and the account code value is multiple levels down it has made it more convoluted.
Right now I’m doing the following - This is very manual and visual leaning because I had some weird behaviour when I was trying to cleanse where I have two account codes which are identical but Silverfin won’t/can’t match them for unknown reasons:
{% comment %} creating empty arrays to shuffle data about {% endcomment %}
{% assign adjustmentList = '' | split: '|' %} {% comment %} finally array we use for final table {% endcomment %}
{% assign existingAccountCodes = '' | split:'|' %} {% comment %} array we use to out all the account codes {% endcomment %}
{% assign transactionListToCleanse = '' | split: '|' %} {% comment %} array we use to dump all the transactions {% endcomment %}
{% assign thisTransactionToCleanse = '' | split: '|' %} {% comment %} array we use to dump all the transactions for the current transaction we want to cleanse {% endcomment %}
{% for adjustment in period.adjustments.external %} {% comment %} loop through all the external adjustments in the period {% endcomment %}
{% assign adjustmentTransaction = adjustment.transactions.first %} {% comment %} we only need to get one transaction per each adjustment since we know it will be for the same account code at this level {% end comment %}
{% push adjustmentTransaction.account.original_number to:existingAccountCodes %} {% comment %} put the account code of each into account code list {% endcomment %}
{% push adjustmentTransaction to:transactionListToCleanse %} {% comment %} Also take the entire transaction {% endcomment %}
{% endfor %}
{% comment %} capture the unique account codes{% endcomment %}
{% capture uniqueAccountCodes %}
{{ existingAccountCodes | uniq | join:',' }}
{% endcapture %}
{% comment %} convert the above capture into an array we can loop through {% endcomment %}
{% assign finalAccountCodes = uniqueAccountCodes | split:',' %}
{% comment %} for each account code we then want to go through every transaction and first of all check for matches so we can continue the logic later {% endcomment %}
{% for account in finalAccountCodes %}
{% comment %} this is a work around which realistically should be used {% endcomment %}
{% if account == finalAccountCodes.first%}
{% assign theFirstTransaction = transactionListToCleanse.first %}
{% push theFirstTransaction to:adjustmentList %}
{% endif %}
{% comment %} this goes through every account code and checks the transactions account codes match. This is where my issue is {% endcomment %}
{% for transaction in transactionListToCleanse %}
{% if account == finalAccountCodes.first %}
{% else %}
{%capture transactionOriginal %}{{ transaction.account.original_number }}{% endcapture %}
{{ transactionOriginal }} - {{ account }} - {% if transactionOriginal contains account %}Yes{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
The way I am trying to do this feels so gross I am certain there must be a better way which yields better results. The way I am doing does not even guarantee a match since for some reason Silverfin thinks the first and last values in the array(s) are not a match even if the values are identical (I know this due to visual debugging I’ve done which is accounted for in the code above - I have tried several operators: contains, ==, !=, etc - all yield the same issue).
I tried to approach it from a debugging perspective with the following assumptions -
- That Silverfin could be treating them as objects and since they are not from the same adjustment transaction so it won’t match
- That it perceives one as a string and one as an int
Regardless if I try to force cast the values or use different operators, Silverfin can’t match the first and last values in the array(s). I tried to get around this in the code above by auto pushing the first and last values but I can’t always guarantee that the first and last values will be a match. So this is logically redundant too.
Example - If you comment out the code which checks if we are looking at the first Account code value, then the first value in my demo code shows this (the yes means that Silverfin thinks it is a match):
240301.000 - 240301.000 -
140502.000 - 240301.000 -
140301.000 - 240301.000 -
141200.000 - 240301.000 -
You can clearly see that the first two are identical, but for some reason they won’t match. In the next set of values I get this:
240301.000 - 140502.000 -
140502.000 - 140502.000 - Yes
140301.000 - 140502.000 -
141200.000 - 140502.000 -
Which demonstrates It can match and it continues to work until it gets to the last two in the list.
I did try to see if there was any documentation regarding filtering arrays or filtering drops a bit more precisely but couldn’t find anything that worked for my use case…
Any corrections, advice, suggestions welcome. Think I’ve hit a bit of a knowledge cap with this one