My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
Go to Article
Advanced Search 

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.

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.

    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

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro

    ADVISORAMA
    There's none so blind as they that won't see.
    -- Jonathan Swift, British writer

    ARTICLE INFO

    FileMaker Advisor

    Web Edition: 2007 Week 40, Doc #19259

    Print Edition: October/November 2007, Page 36

    FREE ACCESS FREE ACCESS

    SUBSCRIPTION STATUS
    You are not signed-in. If you are a subscriber to this publication, sign-in above to access locked articles. To subscribe or renew go to www.AdvisorStore.com.

    Subscribe to FileMaker Advisor Magazine

    Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

    FileMaker.Advisor.com

    Subscribe to Advisor Basics of FileMaker Pro

    Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

    FileMaker.AdvisorBasics.com

    Showcase Your Smarts

    Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!

    AdvisorTips.com

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2008 Advisor Media, Inc. 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, Inc. 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
    osboj035-05 posted 10/01/2007 modified 12/01/2008 04:11:48 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 12/03/2008 05:05:58 PM