Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages

Shopping Cart
Shopping Cart


Free Newsletter


Privacy Policy

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.


 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

ApplyToRange ( function ; start ; end ; step ; separator )

Rate this function:  

  Average rating: 3.7  (48 votes)
  Discuss this Custom Function

Debi Fuchs, Aptworks Consulting

Speedily (and using limited recursion) apply an "inline" function across a range of up to one million numbers.

Sample Input:
ApplyToRange (

Sample Output:

 Then copy & paste into FileMaker Advanced's Edit Custom Function window.


CUSTOM FUNCTION: ApplyToRange ( function ; start ; end ; step ; separator )
© 2008 Debi Fuchs of Aptworks Consulting,

Speedily (and using limited recursion) apply an "inline" function across a range of up to one million numbers.


ApplyToRange ( "[n]"; 1; 1000; 1; " ")
// --> "1 2 3 ... 1000"

ApplyToRange ( "[n]"; 3; -3; -1; ";")
// --> "3;2;1;0;-1;-2;-3"

ApplyToRange ( "[n]^2"; 1; 4; 1; "¶")
// --> "1¶4¶9¶16"

ApplyToRange (
"; "
) // --> 1:1/1/2008; 2:1/8/2008; ...; 53:12/30/2008

ApplyToRange( "case(lg([n])=int(lg([n]));1)"; 1; 1024; 1; 0)
// --> "1101000100000001..."

NOTE: See "Apply" to apply a function to a single value. See "ApplyToList" to apply a function to the elements of a list rather that a range of numbers. For example, if you want to add 2 to every item in a list:

1) Don't do this (slower):
ApplyToRange( "GetValue(myList; [n])+2"; 1; ValueCount( myList ); 1; "¶")

2) Do this (faster):
ApplyToList( "[n]+2"; myList; "¶" )

CREDITS: Thanks to Agnès Barouh for the idea of the "[n]" style function call syntax, and to Ray Cologon for ideas about local variables within custom functions.

USAGE: ApplyToRange returns the results, delimited by "separator", of repeatedly evaluating the string "function", each time assigning to placeholder "[n]" one value in the range from "start" to "end", with a step between values as specified by the "step" parameter. For convenience in creating numbered lists, use placeholder "[i]" to represent the position of the element within the range, starting with an index of 1. Also, for compatibility with "Apply" and "ApplyToRange" the placeholder "[t]" is also provided, but there is no reason it should be needed in this function, as numbers and evaluated numbers are the same thing.

FYI: While their implementations are quite different, ApplyToRange is similar in functionality to the CustomList function by Agnès Barouh: Both functions apply a function to a range of numeric values. However, ApplyToRange is all about sets, whereas while CustomList is all about building a list, so they have different focus. For example, null elements are intentionally NOT filtered from the result set of ApplyToRange, as it represents the mapping of elements to individual elements, rather than to a list at large. (To cull null values from the result set of ApplyToRange, try the CullNulls CF.) Another notable difference is that ApplyToRange does recurse (unlike CustomList, which is brilliantly non-recursive), but only minimally (see below).

IMPLEMENTATION: ApplyToRange creates an "index list" of the values 0 through 1000, using it to create a string of 1000 Let statements, each representing one value in the range. After evaluating the result, it recurses in binary fashion (calling itself twice not once) on subsequent 1000-element batches of the range, such that the stack depth grows only logarithmically, not linearly. For example, when called on a range of one million values, ApplyToRange will be called 1000 times, but reach a stack depth of only 10 CF stack frames. This leaves room to use other custom functions (including ApplyToRange) within the "function" argument of ApplyToRange. ApplyToRange is maximized for speed. Suggestions for further optimization are welcome!

LAST MODIFIED: 13-AUG-2008 by Debi Fuchs of Aptworks Consulting

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

This is my Custom Function and I want to edit it


There are no comments yet. Be the first to post a comment about this Custom Function! Please try to keep it brief & to the point. Anyone can post:

Your Name:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 7 + 4 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. HexUUIDToNum_cf (_uuid)
  (Sat, Jun 16, 1:55pm)
2. httpResponseCode ( responseHeaders )
  (Tue, Jun 12, 10:40pm)
3. FindDuplicateCharacters ( string )
  (Fri, Jun 08, 5:01pm)
4. FieldRepetitionLast ( field ; maxRepetition )
  (Wed, Jun 06, 6:05pm)
5. CountModifiedRecords ( NameTimestampField ; StartTimestamp ; EndTimestamp )
  (Mon, May 28, 8:23am)
6. JSONArrayLength ( JSONArrayStr )
  (Fri, May 25, 7:46am)
7. interpolation (y1; y2; y3; x1; x2; x3; x1y1; x2y1; x1y2; x2y2; rnd)
  (Sat, May 19, 3:55am)
8. @JSONFormatElements ( json )
  (Tue, May 15, 3:31am)

RSS Feed of Custom Functions