### Title

Repeating calculation to add the first X related records?

### Post

I am struggling to build a calculation that sums the first X records of a related table (for a chart). The records in the related table are sorted in descending order, and I want to sum the values of number fields for the top 5, the top 6-10, and the top 11-25.

How would I go about this?

Any way you can give each group of records a common value? That would be simplest. There are calculations that can use a serial number (if there are no gaps in the order) that can do this. Let me know if this sounds possible and I'll expand on this in a subsequent post.

If not, perhaps by using evaluate and List functions.

Let ( L = LeftValues ( List ( RelatedTable::ValueField ) ; 5 );

Evaluate ( Substitute ( left ( L ; length (L) - 1 ) ; ¶ ; " + " ) )

)

Note: left ( L ; length (L) - 1 ) strips off a trailing return produced by using LeftValues.

Modifying the above expression by using MiddleValues instead of LeftValues will return your other sub totals.