Welcome to the first installment of a two-part series on producing reports using the virtual list technique, or more properly, collection of techniques. Download the Demo file: VLR-part-1.zip
Invented and popularized by Bruce Robertson, virtual lists are incredibly flexible, and have made a number of appearances here in the past, includingâ€¦
- Long Documents in FileMaker 11
- Virtual List Charts, part 1 & part 2
- Summary List + Virtual List
- Conditional Subsummary Report in Browse Mode
The Basic Idea
In case you arenâ€™t already familiar with virtual lists, in a nutshell, you create a special utility table in your solution, and pre-populate it with â€śmore records than youâ€™ll ever needâ€ť (there are 10,000 in todayâ€™s demo). The records in this table will derive their data â€śvirtuallyâ€ť, by reading it from some sort of arrayâ€¦ typically, one or more variables.
There are various ways to implement virtual list reporting, a.k.a. VLR, and today weâ€™re going to concentrate on one particular approach that has worked well for me recently. Specifically, weâ€™re going to use the Multi-Find technique to summarize values from Sales Data and Web Visits, and push that data into $variables, or, more accurately, $variables[withReps], which will be parsed by an unstored repeating calculation in the virtual list tableâ€¦ with table columns corresponding to individual named $vars, and table rows corresponding to $var[repNumbers].
If youâ€™re already familiar with the virtual list technique the preceding paragraphs probably make at least some degree of sense; if you arenâ€™t and/or they donâ€™t, donâ€™t worry, things should become clearer as we explore the examples.
Itâ€™s a fair question, because on the surface VLR may appear to simply be a more convoluted way to accomplish things that you already know how to do via standard FileMaker reporting techniques. And for basic reporting tasks, I would agree.
But as requirements become more challenging, VLR enables you to generate reports (reports that would normally require the creation of multiple helper calcs and/or utility relationships) without touching table schema in your main solution or making any modifications to the Relationships Graph.
Once the Virtual List table has been defined, the heavy lifting will be done primarily at the scripting levelâ€¦ and of course at the layout level, but that would be true of traditional FileMaker reporting as well â€” in fact VLR layouts are typically simpler than corresponding standard FM reporting layouts.
Bottom line: willingness to invest in a bit more complexity up front can help things run more smoothly down the road. Letâ€™s take a look at the structure of the demo, and then weâ€™ll explore the report examples.
The demo consists of two primary data tables (Sales and Web Visits), the Virtual List table, and a number of supporting tables.
Note that the primary data tables are almost completely pure, i.e., devoid of reporting â€śhelperâ€ť fields, apart from a single summary field in Salesâ€¦
â€¦and one in Web Visits.
The Virtual List table is a study in minimalism as well.
There is a table view, which can come in handy for troubleshootingâ€¦
â€¦and, finally, hereâ€™s the Relationships Graph, which is also extremely basic.
Weâ€™re going to begin with a very simple cross-tab report. Starting from hereâ€¦
â€¦how do we end up here?
As mentioned above, the bulk of the heavy lifting is performed by the reporting script, which begins with some basic prep, and the initialization of a number of $variablesâ€¦
â€¦including $listY and $listT, which end up being populated like so (note that the first row of $listT is intentionally empty):
Next the script loops through the two lists and populates $col_x[rep] variables, where x represents columns 1 through 5, and [rep] corresponds to each iteration of the outer loop, i.e., the numbers 1 through 8 (since there are eight values in $listY â€” assuming youâ€™re running the demo in the year 2016).
At this point the script has loaded up a bunch of $var[reps]â€¦
â€¦which will be parsed by the Virtual List table into an unstored repeating calc field, cell_num_r:
Cell_num_r extracts data from the aforementioned $var[reps] by translating calc reps into $var column numbers, with the ID value of each table row corresponding to a $var repetition number. The column translation works because Get(CalculationRepetitionNumber) enables each rep of the calc to know its own rep number.
If youâ€™re wondering about the â€śâ€ť after the ID in the calc def, it ensures that the calc reps correctly refer to the non-repeating ID field. As an alternative, I could have wrapped ID in an Extend function, but I prefer array notation (i.e., â€ś[x]â€ť).
So, to take a specific example, rep 2 of cell_num_r in row eight will first assemble a $var[rep] named â€ś$col_2â€ť and then will Evaluate that var, returning 1072493.34.
The remainder of the script is devoted to displaying the report.
Here is the report in layout mode, with reps 1-5 of cell_num_r individually placed from left to right, and reps 2-5 formatted for readability to display zero decimal places.
And, as we saw at the outset, here is the end result.
Note that the reporting script ends with a Pause step to facilitate $var exploration via the Data Viewer. You will need to unpause before moving on to the next example.
Okay, that was a fair amount of explanation, but it also took care of a lot of foundation-level material. Moving forward, we will focus on specific points of interest in reports 2 â€“ 6.
Here we have a year/month cross-tab Sales reportâ€¦
â€¦and here it is in layout mode. We are going to use the same layout for report #3 as well, so there are a couple of merge variables in place of hard-coded text labels. In the body we have reps 1 through 14 of cell_num_râ€¦
â€¦and the totals in the trailing grand summary come from a corresponding 150-rep summary field, defined like so (we donâ€™t need to specify the number of reps for the summary field; they are inherited automatically from cell_num_r):
The script for Report 1 was intentionally written to be as transparent as possible, e.g., it employs no custom functions and uses only static variable declarations. In the remainder of todayâ€™s reporting scripts we are going to make things more efficient by utilizing a pair of custom functions.
First, CustomList allows us to replace thisâ€¦
CustomList also facilitates building the month number list.
(These are the most simplistic examples of what this amazing CF can doâ€¦ even if you normally avoid CFs on general principle, I recommend making an exception for this one.)
Second, SetVarByName facilitates the creation and population of $col_3 through $col_14, i.e., months 1 â€“ 12. Here the CF merely eliminates a bit of tedium; in reports 4, 5 and 6 it will play a more substantial role.
Finally, note the use of the custom paper size trick to gain an extra horizontal inch for the report layout.
As mentioned, this report uses the same layout as report #2, although this time weâ€™re summarizing Web Visits instead of Sales.
This illustrates one of the advantages of VLR, because, having already built report #2, I was able to bring report #3 online in (literally) five minutes by duplicating the script, modifying the lines highlighted in yellow, and adding the lines highlighted in green.
This is an expanded version of report #1, with sales order counts and percentages.
SetVarByName gets more of a workout here.
Here weâ€™re taking report #4 one step further, by adding a trailing grand summary with three-year averages looking backward from todayâ€™s date.
Once again, thanks to VLR, an additional block of script code accomplishes this, and we donâ€™t need to touch the Relationships Graph or table schema.
Note that in line 63 above we set $cNum to 22. One of the tricks VLR keeps up its sleeve is to work some of the magic in higher-numbered column $vars. The report layout displays reps 1-12 of cell_num_r in the body, and then reps 22-32 of the same field (not a summary field) in the trailing grand summary.
If you display the virtual list table before generating the report and scroll it righward like so, you will see numbers like these appear in row 8 during report generation.
As mentioned earlier, what you see in your copy of the VLR demo wonâ€™t match what you see here because sales data is auto-updated on demo startup; also if youâ€™re running the demo in the year 2016 the row will be 8 â€” otherwise it will be higher. (If itâ€™s lower, please clue me in on your time travel secret.)
Our final report today is a further refinement on reports 4 & 5, with two new columns at the far right showing the number of web visits and percent of those visits that resulted in a purchase.
Unlike a standard FileMaker report, which would typically be based on a data table such as Sales, the virtual list table doesnâ€™t care where the data comes from, and you are free to combine data from unrelated tables. Have your script populate the $vars, and the virtual list table will do the rest.
At the risk of stating the obvious, nothing here is carved in stone. If youâ€™ve made it this far, you are probably thinking of ways you can adapt or improve on some of these ideas for use in your solutions. Maybe youâ€™d rather use $$vars than $vars, or would prefer to generate a single 2-dimensional delimited $array (or $$array), and parse the data from that. Those approaches have been explored in some of my earlier virtual list articles, and there are pros and cons associated with each.
At any rate, today weâ€™ve made the tiniest scratch on the surface of what can be accomplished with Virtual List Reporting. In part 2 weâ€™ll dig a little deeper.
FMT Staff Note: IF you would like any of Kevin's tip or techniques incorprated into a solution or project contact him at his website below.
Hello and welcome. Iâ€™m Kevin Frank, and Iâ€™ve been using FileMaker Pro since the late â€™80sâ€¦ professionally since 1995. The expression â€śhackâ€ť has both positive and negative connotations. Here it is defined as â€śa tip, trick or technique that helps you solve a problem,â€ť and the best hacks are the ones that can be re-used and modified to meet a variety of challenges. Or, put another way, as I read recently in Street Fighting Mathematics, â€śA tool is a trick I use twice.â€ť
Kevin Frank and Associates provides custom FileMaker database solutions for business, government, education and non-profit clients. With over 20 years experience, we are certified FileMaker Developers with a solid reputation for high quality results. We invite you to call us today for a no-charge, no-obligation phone consultation.
To find many more in depth articles from Kevin and some must have tools and services visit his site at the link below:Website: www.filemakerhacks.com