Repeating list datafields and calculations

I am working on an ownership schedule for an LLC agreement. I am using repeating variables to contain ownership information, because there can be up to n owners. Each row of the table contains the owner’s information (name, capital contributions, and units), which are all repeating datafields stored under the owner concept.

However, one column of the table is for the ownership percentage. I need this column to calculate each owner’s ownership percentage by dividing that owner’s number of units by the total number of units held by all owners.

I have tried various methods to do this. I think the for-loops guidance has the best chance of working, so I tried creating a snippet but I still could not get it to work. I reviewed the @for-calc example and I think I would need to somehow @merge-table to make this work, but it seems like @merge-table only works if you trying to put together rows of a table not.

Can you provide me with a way to include a number in a table that is a percentage derived from an entry in a repeating list divided by the sum total of that datafield in the repeating list?

Essentially, I want to do @percentage-divide(#owners^units, @sum(#owners^units) for each row.

Hi Elmer,

As explained on the page regarding repeating lists (Repeating list datafields – Help) there are situations where you need to “escape” the extraction of list-values that happens in a table row.

  • In the first #owners^unit you do not want this escape, as the first argument to @percent-divide must use the number of units for that particular owner. It is therefore justified to have the software automatically extract the right value from the repeating-list.
  • In the second #owners^unit however, you do want the escape to take place, because you want to use all units in order to take the sum of all the elements in the repeating list. You therefore need the underscore to “escape” the automatic extraction, i.e. prevent it from taking place.

As I understand your question, there is no need to involve a @for-calc or @merge-table here.

Thanks, Maarten. It worked like a charm. I am still wrapping my head around using the “_” when dealing with repeating list variables, so the guidance is appreciated.

I guess you could summarise it as follows:

Let’s assume for the purposes of this explanation that we have a repeating list text datafield #concept^repeating-list with entries “alpha”, “beta” and “gamma”.

A repeating list datafield is used in two ways: (i) as a ‘normal’ list datafield (i.e. including all elements entered into the list); or (ii) as a reference to a specific element inside the list.

Which of these two ways is used by the software is in principle determined by the location of the reference to the repeating list datafield:

  • If #concept^repeating-list is used inside a paragraph of a non-repeating clause, it will be understood as a reference to the entire list. For our repeating list text datafield #concept^repeating-list, this would be the list “alpha, beta, gamma”. Inside a paragraph of a non-repeating clause, you could therefore use this datafield as the argument in e.g. a enumeration special function such as @enumerate-and(#concept^repeating-list), resulting in: “alpha, beta and gamma”.

  • If it is used in a repeating clause, a table or a for-loop, the reference to the repeating list datafield will be understood as a reference to the specific “nth” element of that occurrence. I.e. in the first loop, the code #concept^repeating-list will be understood as a reference to “alpha”, being the first element of our datafield. In the second loop, it will be understood as a reference to “beta”, and in the third loop as a reference to “gamma”. So you could not use #concept^repeating-list inside of the above-mentioned enumeration special function @enumerate-and(#concept^repeating-list) because the reference #concept^repeating-list is understood as a single text entry (whether it be “alpha”, “beta” or “gamma”).

In some cases, however, you will want to refer to the entire list even when inside of a repeating clause, a table or a for-loop. For example when you want to check for the total number of entries inside of the repeating list datafield (e.g. for the purposes of a condition). In these cases, you would use the underscore as indicated above: #concept^_repeating-list, thus forcing the software to handle this specific reference to the datafield as a reference to the entire list, even though it is located inside of a repeating clause, table or for-loop.


Thanks, for the explanation. I think I am still digesting, but this additional guidance is very much appreciated.

On a related note, is there a function to rearrange the items in an enumerated list, so that they are in alphabetical order?

For example, if you had the repeating list, but the user put in “alpha”, “gamma”, and “beta” @enumerate would return them in that order. Is there a way to get @enumerate to organize them alphabetically?

There is indeed a way to have them sorted alphabetically: the @sort special function (Special functions – Help).

For our hypothetical datafield, it would look as follows: @enumerate-and(@sort(#concept^repeating-list)).

Hi Maarten,
was looking for some answers in the forum and your help here was applicable for my issue.

I have a table for repeating list and my @sum is not working.

||Factuurnummer||Factuurdatum||Vervaldatum||Bedrag||
||-------------||------------||------||-----------||
||#factuur^nummers||#factuur^data||#factuur^vervaldata||#factuur^hoofdsommen||
|| || || ||@sum(#factuur^hoofdsommen)||

Before reading this post I added also the @list, but was not effective, so changed to your example. I just want the sum of all #factuur^hoofdsommen to be in a last row below. I get multiple rows and not the sum. I’m afraid the extra row is making it problematic, no idea how to solve this

Hi Sarah,

Assuming the #factuur^hoofdsommen datafield is a repeating list datafield, you will have to use the underscore to “escape” the repeating character of the datafield and force Clause9 to handle this reference as a reference to the entire list. You would therefore type @sum(#factuur^_hoofdsommen).

Due to the fact that the reference to #factuur^hoofdsommen was included in a table, Clause9 assumes it is your intention to repeat the table row for each entry in the repeating list datafield instead of as a reference to the list as a whole, which is why we have to “escape” the repeating nature with the underscore.

that’s it!! thx!
What 1 underscore can do!!!

1 Like

If i were to use this @sum(#factuur^-hoofdsommen) in another clause, I guess it will not work. How would I refer best to this then?

The only thing the use of the underscore does, is force Clause9 to handle the datafield as a list in all cases. So if you would use it elsewhere (in a non-repeating context) it would still just work as a list datafield.

Best practice is to always include the underscore in case you want to use a repeating list datafield as a list and to drop it if you are using it in a repeating context where it actually should repeat (e.g. in a table row or repeating clause) instead of used as a list.

ok! thx!