Brian Dunning's FileMaker Custom Functions

Portal_Row_Number ( ID ; Field ; Counter )

Find a record number from its position in a portal row.

  Average rating: 4.1 (31 votes) Log in to vote

Simon Ward   Simon Ward - Show more from this author
Linear Blue

Share on Facebook Share on Twitter

  Sample input:
Portal_Row_Number ( 2 ; Related::_kp_Field ; 1 )
  Sample output:

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This calculation will display which portal row a record is based on a Pirmary table and Line items table. There must be a relationsip between the Line Items table and its self based on the Primary Table Key. i.e each line item will display the same portal that would be seen from the Primary record. In the Calculation the Related::_kp_Field is over this self relationship.



John Buckingham   John Buckingham, microGuidance
Nov 29, 2016
Hi Simon

Thank you for posting this CF. I couldn't get it to work in FM14 but your concept was so elegant that I've slightly modified the code and it seems to work for me.

The changes I've made are; including totalRows in the parameter set (so it is determined once rather than for each iteration) and including the 'getField' function in the getNthRecord element.

So, my version of your CF is now:

Case (

Counter > totalRows ; "0" ;

ID = GetNthRecord ( GetField ( Field ) ; Counter ) ; Counter ;

Portal_Row_Number ( ID ; Field ; totalRows ; Counter + 1 )


I couldn't understand the part of the description regarding the requirement for the TO relationship definition, but the modified code seems (so far!) to work on any portal without any further TO being required. All I send the CF is; 'getfield ( the PrimaryKey field )' for the current portal row, 'getfieldname ( PrimaryKey field)', the number of rows of the current portal relationship, & '1'.

Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 16 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: