My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
   
SUBSCRIPTION STATUS
If you are a subscriber to this publication, sign-in to access locked articles. To subscribe or renew go to www.AdvisorStore.com.
Go to Article

ADVISOR TIPS

Faster FileMaker Pro Value Filtering

Discover a custom function you can use on large lists to filter them quickly.

By John Mark Osborne, Database Pros president and owner, and FileMaker Advisor technical editor


Back in the April/May 2005 issue, I wrote a tip titled "True Value Filtering." It demonstrated a recursive custom function that compares two return-separated lists and shows the values that were different between the two lists. It's the opposite result of the FilterValues function that returns the values that are the same between two return-separated lists.

For example, say you have two return-separated lists:

List 1:

A
B
C
D

List 2:

B
C

The result of the formula would be:

A
D

The current version of the recursive custom function looks like this:

FilterList(List1; List2; Len)

Case(

Len > 0;

FilterList(List1; List2; Len - 1) &

Case(

not PatternCount ("¶" & List2 & "¶"; "¶" & GetValue(List1; Len) & "¶");

GetValue(List1; Len) & "¶"

)

)

You call this custom function with a calculation such as:

FilterValueList(MyListField1; MyListField2; ValueCount(MyListField1))

Unfortunately, this approach can be slow with large lists. Fortunately, Kieren MacMillan came to the rescue with a formula that doesn't use recursion. Instead he uses the Substitute function for significantly greater speeds on large lists. He even gives the option to output three different ways as you'll see at the beginning of the custom function. Otherwise, the custom function is heavily notated with comments to better describe this complex formula. Here's the custom function:

ListDifference(listA, listB; output)

/*
This is a non-recursive difference-of-lists function.

output = 'A' returns anything in listA which is not in listB;
output = 'B' [or empty] returns anything in listB which is not in listA;
output = 'both' returns anything in either list which is not in both.
*/

Case(

/*  Short-circuit for empty parameter(s).  */
output = "A" and IsEmpty ( listA ) ; "" ;
output = "B" and IsEmpty ( listB ) ; "" ;
output = "both" and IsEmpty ( listA ) ; listB ;
output = "both" and IsEmpty ( listB ) ; listA ;

/*  No short-circuits -- proceed.  */

Let([
/*  Build the 'before' list, based on the output choice.  */

@_listBefore = Case ( output = "both" ; listA & "¶" & listB ; output = "A" ; listA ; listB ) ;

/*  Double-tokenize, to avoid 'consecutive duplicate value' bug.*/

@_listBeforeDT = Substitute ( @_listBefore ; ¶ ; "¶¶" ) ;

/*  Build the 'thru' list, based on the output choice.  */

@_listThru = Case ( output = "both" ;  FilterValues ( listA ; listB ) ; output = "A" ; listB ; listA ) ;

/*  Build a Substitute formula from the two lists.  */

@_header = "Substitute ( " & Quote ( ¶ & @_listBeforeDT & ¶ ) & " ; [ \"\¶" ;
@_footer = "\¶\" ; \"\" ] )" ;
@_formula = @_header & Substitute ( @_listThru ; ¶ ; "\¶\" ; \"\" ] ; [ \"\¶" ) & @_footer ;

/*  Fix the double-token subsitution parameter(s), to avoid erroneous hard-return removal.  */

@_formulaFixed = Substitute ( @_formula ; " [ \"\¶\¶\" ; \"\" ] " ; " [ \"\¶\¶\" ; \¶ ] " )

];

If(

/*  Exit on formula length error.  */

Length ( @_formulaFixed ) > 30000 ; "ERROR: Excessive formula length." ;

/*  Evaluate the formula.  */

Let([

@_resultDT = Evaluate ( @_formulaFixed ) ;

/*  Un-double-tokenize.  */

@_result = Substitute ( @_resultDT ; "¶¶" ; ¶ )

] ;

/*  Eliminate the leading and trailing hard returns, and return the final result.  */

Middle ( @_result; 2; Length ( @_result ) - 2 )

))))

To call this formula from a calculation, you might use the following formula:

ListDifference(MyListField1; MyListField2; "A")

When you get this custom function entered properly, try it out on a large return-separated list and watch how fast it runs! In an example I ran using a list of 3,172 values compared to a list of six values, the recursive custom function took nearly 30 seconds and the custom function using Substitute took less than one second.

John OsborneTechnical editor John Mark Osborne is president and owner of Database Pros, offering FileMaker resources on the Internet. He is author of Scriptology, a speaker at FileMaker Developer Conferences and Macworld conferences, and a trainer for the Professional Training series created by FileMaker, Inc. http://www.databasepros.com jmo@filemakerpros.com

Printer-friendly
page layout

Faster Value Filtering

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    ARTICLE INFO

    Web Edition: 2007 Week 40, Doc #19259

    FREE ACCESS FREE ACCESS

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro, Software Development

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2010 Advisor Media, LLC. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, LLC in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    Hosted by Prominic.NET Website powered by
    LOTUS SOFTWARE
    ztfmfd0710 osboj035-05 posted 2007-10-1 mod 03/18/2010 03:09:21 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 03/18/2010 05:32:31 AM