CASE: sort descending and ascending

Let’s say you want to display the details of a custom collection you’ve created, it’ll display the order in which the data has been inputted:

{% for depr in custom.depreciations %}
| {{ depr.description }}  | {{ depr.value }}  |
{% endfor %}

Output:
07

If you want to alter the order of your forloop, you can by assigning your custom-collection to a variable and put a sort filter on it, like this (for instance ordering on the object value:

{% assign depreciations = custom.depreciations | sort:"value"  %}

{% for depr in depreciations %}
| {{ depr.description }}  | {{ depr.value }}  |
{% endfor %}

Output:
25

So you assign the custom collection to a variable that’s sorted on a certain object with the sort-filter:

{% assign depreciations = custom.depreciations | sort:"value"  %} 

The new variable has to be used of course within your forloop, or it won’t work:

{% for depr in depreciations %}
| {{ depr.description }}  | {{ depr.value }}  |
{% endfor %} 

If you want it sorted reversed (descending), you can add a reverse-filter to it, like this:

{% assign depreciations = custom.depreciations | sort:"value" | reverse  %}

{% for depr in depreciations %}
| {{ depr.description }}  | {{ depr.value }}  |
{% endfor %} 

I’m looking to use the sort function when arranging some account summaries.

Currently our mapped account numbers are with IRIS, and are not fixed width numbers, as such we have accounts #5, #52, #522, #523 - #526, etc.

We would like these to be sorted numerically (I.e. 1, 2, 3 etc. - not 1, 10, 100, 2, 20, 22, 3, 35, 352, etc.)

Because Silverfin examines the account numbers as a string, examining the code using characters from the left, I don’t know whether this is possible.

Do you know of a solution?

Example code, which does NOT sort the account numbers:

{% stripnewlines %}
|{% t “Account number” %}
|{% t “Account name” %}
|{% t “Original import” %}
|{% t “Adjustments” %}
|{% t “Total in year” %}
|{% t “Total prior year” %}
|
{% newline %}
|—10%—
|—25%—
|—10%—
|—10%—
|—10%—
|—10%—
|—25%—+
{% newline %}

{% for acc in period.accounts %}
|{{ acc.number }}
|{{ acc.name }}
{% assign $1 = 0 %}
{% for trans in acc.transactions %}
{% assign $1 = $1+trans.value %}
{% endfor %}
|{{ $1 | currency_dc }}
|{{ acc.value-$1 | currency_dc }}
|{{ acc.value | currency_dc }}
|
{% newline %}
{% endfor %}

{% endstripnewlines %}1 | currency_dc }}
|{{ acc.value | currency_dc }}
|
{% newline %}
{% endfor %}
{% endstripnewlines %}

Results in:

Hi @ThomasB,

From an accounting perspective I’d expect acc 1 to be followed by 10,100 instead of 2 to be honest. Because account 10 and 100 are part of account 1, no? Or am i missing something here regarding IRIS chart of accounts?

Anyway, for a workaround I’m thinking of this:


{% assign accounts = period.accounts %}


{% for acc in accounts %}
  {% assign nbr = acc.number | remove:"." %}
  {% if nbr.size == 1 %}
    {% assign array_1 = array_1 | append:acc.number | append:";" %}
  {% elsif nbr.size == 2 %}
    {% assign array_2 = array_2 | append:acc.number | append:";" %}
  {% endif %}
{% endfor %}

{% assign accounts_array = array_1 | append:array_2 %}
{{ accounts_array }}
{% assign accounts_array = accounts_array | split:";" %}

* * * 

{% for acc in accounts_array %}
  {{ acc }}
{% endfor %} 

So what we’d do here, is look at the length of a number, and assign them to specific arrays (length one is array 1, length 2 is array 2, … ). So this way you actually order looking at the length of it.
After that, you assemble one array where you can loop through it.

Is that something workable for you? Because if you expect this to oder this in every template you call upon accounts-drop, this might be way too much of a workaround.
If it’s something rare, thetn it might be workable (hence my question at the beginning if this is something specific :slightly_smiling_face: )

Hi,

Thanks for the information. In certain cases we would like adjust the standard account template to sort the details based on the values, not alphabetically on the title.

What do we need to adjust in the copy of the standard template?

Thanks for the info!

Hi @MathiasRosseel

you can sort on value, we have an article in the community how to do so :

Hopes this helps you further.

Kind regards
Sofie

This could be usefull in some standard Silverfin templates:
for example Account template: Invoices te be received

sort by nr. or Date

Is it possible to build something like this in the configuration field?

Actually @AlexanderDB, that’s a great question.

Either we make the templates to be able to sort on anything, or we can indeed change our code so users can decide for themselves on which column needs to be sorted.
for now, there isn’t though… But I’ll definitely investigate this further, what the best approach would be in this.

Thanks for the feedback everyone!