In the last post we talked about the process of learning the fundamentals of Monarch, and this leads nicely into a discussion of Monarch’s unwritten (?) cardinal rule and how we can take advantage of it.
What’s the rule? Simply put, “Don’t allow the user to alter the original data in any way with Monarch”.
What’s the effect of the rule? No risk.
There’s no way that you can corrupt your report file with Monarch when learning how to model reports. That’s entirely unlike the messing around that I did with early spreadsheets and databases. You’ll never lose data or edit the original values permanently. Modeling is totally safe.
Just be carefully when exporting.
And the knowledge that you can do no wrong affords you great comfort.
You can try new things. You can experiment. You can fail. And if you do, all is not lost, save for perhaps a few minutes of your time.
But you may very well succeed, and when you do it’ll make all of your efforts worthwhile.
The Big Win
Such was the case for Grant Perkins, the UK-based consultant who pioneered an exceedingly useful little trick that’s now referred to as the “guru trap”. It’s a technique that permits a model to use append templates to add data to a record when the appended data physically appears subsequent to – not prior to, as is normally the case with append templates – the detail record displayed in the report.
Grant has contributed to ExcelWithMonarch.com in the past, and I’m pleased to have his input for you again today. Take it away, Grant…
I’d heard about Monarch and picked up a copy and spent a year or so using it on and off on a few projects. When a new reporting challenge was presented I looked at Monarch first to see if I could get the data from standard reports (lots of complex time calculations already done there) rather than reinvent the wheel. Often I could, sometimes I couldn’t.
A couple of years on, I extended the use somewhat when we needed to retrieve data, including a lot of long form text, from an external supplier’s system. The only method available to recover the information was to screen scrape using a screen emulator on the dumb terminal/dial up connection they had provided. A colleague who had authorized access to the supplier system wrote the screen scraping script and we ended up with a large file of screen dumps, mostly with data consistently positioned but there were a few exceptions that required conditional field calculations to extract and format ready for upload to our database.
Hmm. Monarch could be deployed much more widely than I had imagined.
Soon after that I discovered the Monarch forum and shortly after that was pleased to be provided with a copy of the CD that was made available to attendees of the 2003 Datawatch User Conference. On that CD were some presentations called ‘Voodoo Monarch’ that looked rather interesting …
Suddenly it was as if a door had opened and the lights came up bright. There was SO MUCH more one could do with the features and functions in Monarch than I had previously identified.
So I started to experiment hoping for success but knowing that failure would be a valuable learning experience anyway and cost little time.
The approach I adopted was to look at a problem report situation and come up with a few ideas that might or might not work. Off-the-wall was good for seeking out these ‘Voodoo’ approaches. Sometimes I would find something that worked without being sure why it worked.
As the ideas are applied to more and more examples of problems (forums are a great source of learning material) one can start to work out what is going on and perhaps even why!
The Guru trap, as it became known, had its origins in a rather nasty little data dump file (rather than a report whose appearance, nasty or otherwise, had been “designed in”) in which the master detail record was, at a minimum, about 4 lines long but some records could be several lines longer. Add to that that fields were not always present in all records or, apparently, in the same order and it looked like a completely unintelligible mess.
But two Monarch features came together to make the extraction viable in a single pass. A single pass through the report is always a good objective though there is no reason at all to stick inflexibly to that ideal if multiple passes through the report simplify the model development task and produce a quicker and/or more flexible result.
Firstly the undocumented one:
There is nothing in the processing of a report to prevent two or more templates sharing the same trap or indeed extracting the same ‘data’.
By sharing the same trap as a Detail template an Append template is, effectively, forced to reset every time Monarch finds a new detail record. In effect, this allows detail records to be extended beyond the notional limit of the number of lines that can be included in the trap sample. (This is counter intuitive to the ‘rule’ that Append data must always appear BEFORE detail data, although in fact rules in the design philosophy are not broken – just adapted slightly to suit the purpose. Well, after all, what are rules for?)
That means that if your shortest record has 3 data lines and a blank line before the next record, the sample ‘mask’ cannot be longer than 4 lines. Records with 12 lines therefore become a problem. Being able to create a ‘stack’ of template masks based on the same starting point selection became the objective from an idea that appeared from nowhere one day and proved to work rather well. (It may have been accidental at the time, but who cares if something works?)
The documented feature was the use of the ‘Start Field On’ Advanced Field Property and its ‘Preceding String’ option.
This meant that so long as the content of the report had enough information to uniquely identify the field required, the data could exist anywhere between the current template trap and the next occurrence of the trap. Specifically, as used for this concept, that meant anywhere between the start of one detail record and the start of the next.
It was actually several months before I understood well enough why things worked to be able to start to explain them if anyone asked (and to be confident that they would work reliably!)
Over time a few more possibilities turned up and enhancements in later versions of Monarch added to the array of features and functions available but the primary principle of discovery remains: Try it and see what happens and what new ideas the attempt presents you with.
Visualize the report and gain an understanding of the problem in terms of what you would need to do to get each field, or group of fields, how you need them to be. If Monarch does not immediately present an obvious solution ask yourself what the solution would be and then consider whether there are function(s) or features that might possible be helpful to move you closer to what you need.
[I find that reading the Function(s) help is very useful for keeping possibilities current in my memory as well as for prompting new ideas to try out. Often they are not practicable but sometimes they lead on to success.]
If you get to a “If I could do this ….” situation it then becomes much easier to work out how, using Monarch, you might get there. Trying it out usually costs little time and teaches a lot.
Be prepared to go back a step or two in your efforts.
Finally, be prepared to try something completely different. On any journey looking for a way around a wall is often more successful than attempting to knock it down.
Thanks Grant!
Defining a “guru trap” requires that you employ exactly the same trap characters in the append template as were used in the detail template, in exactly the same positions. This is done regardless of the representative data within the append template sample line.
Next, the field(s) to be captured is/are painted in the sample line. In the advanced options for each field, either of the “String _________ anywhere in the previous line” or the “Preceding string: _________ in current line” options is employed as is necessary, based on the report content.
There’s usually some string literal, like “NOTE:” or perhaps a / character that appears in a date in one of those lines that can be used in the advanced options of the field definition.
This technique is most often used when the data that needs to be appended appears only intermittently – perhaps as infrequently as only once – amongst an otherwise contiguous series of detail rows.
Grant’s experimentation efforts in developing this technique have enabled many reasonably straightforward (now) modeling solutions, which may well have been impossible if not exceedingly challenging without it.
Your experimentation may not be quite so radical. Maybe it will be more along the lines of trying out new functions, or combinations of functions, that you’ve not previously attempted.
Why so serious?
So go ahead and experiment. Have some fun. Risk little. And, above all, continue to find new ways in which you can excel with Monarch.



{ 4 comments… read them below or add one }
Thanks Grant!
I’ve been incorporating the ‘Guru Trap’ more and more, knowing that it ‘just works’. This now gives me a better understanding now of ‘why it works’!
Great job!
I find this post rather abstract and not very helpful. On top of that, since I sense that a fundamental piece of trickery seems to be conveyed here I find it even more frustrating.
Have you ever heard of using an example to teach a point?
Also, there is way too much fluff in this article. Who the heck is interested in how whoever stumbled upon this guru trap – and in this eloquence? Leave that for a bedtime story for your grandchildren, would you?
Disgruntled in Florida – still hoping to get an example out of this
Welcome to the site, Schorschi.
I’m sorry to hear that you didn’t get what you’d hope out of this post.
That said, if you found it to be rather abstract, I believe that was the intention, in that it’s not a click-here-click-there type of lesson. Instead, it is my impression that Mr. Perkins is encouraging experimentation and that users pursue their own techniques with the software.
Monarch is somewhat different from many other software packages. While its usage can be very straightforward, there are techniques that can be of use that are anything but straightforward and we suspect that there are many such techniques that have yet to be “discovered”.
If Monarch were always simple, there most certainly would not be a need for this site. Perhaps a reader could be kind enough to provide a comment to direct you to a post that he or she believes to be informative or helpful. That might be better than if such direction came from yours truly.
I’d like to think that if you take a few moments to read some of the other content available here, you’ll find a good selection of how-to type content, along with a mix of somewhat (hopefully) entertaining yet relevant pieces, and some that are perhaps more conceptual in nature.
It would be boring to write about the same things, in the same style, continuously, and I’m certain that it would be even worse to read.
As to the writing style, we all write differently, and I’ve been proud to feature content from a number of guest contributors, each from different backgrounds and geographies, so far. In fact, I hope to have even more third-party input here on ExcelWithMonarch.com very soon. I’ve never claimed to have all of the answers, and will gladly facilitate the publishing of good ideas from whoever is willing to share with us all.
I will keep your comments in mind, of course, and will endeavor to include concrete examples where applicable, so as to improve both individual posts, and the site overall.
In attempting to make the site the definitive resource for Monarch users, it will be the ideas shared by the entire Monarch community that will be the site’s greatest success, and I invite you to continue to be a part of this continuously growing group.
Hmm. I have to thank Schorschi for raising some pertinent points that troubled me when writing the piece above.
In fact the lack of a solid and simple example that could be used to get the concept across to readers had troubled me for some time. Even examples that I had prepared for interactive presentations to conferences were lacking in completeness of the message or might seem to be rather explicit to a single obscure problem. Seeing such examples tends to suggest to the viewers that the method will only work for that problem or something similar whereas in fact the approach has some very broad uses.
I did consider picking about 4 variations on the theme, based on ‘live’ problems over the years. But there is an issue about the use of existing ‘real’ data offered in other places and it seems to me that a recreation of reports not only takes quite a lot of effort but is also quite likely to fail to connect with the reader’s own problem as they see it.
Going back a few years the term ‘Voodoo Monarch’ was coined to refer to less obvious approaches to the more difficult (and sometimes truly obscure) reports that systems could produce. There were some fascinating exercises that solved specific problems and showed the power of Monarch (many version past)but that would be unlikely to have everyday use for most users. Or indeed for any users!
However the concepts suggested potential for discoveries by experimentation which is where the idea of overlapping template traps and vertically floating fields (using the preceding string functionality) came from. Working out what they offered to help Monarch modellers and how far they could be applied came later.
Much of that discovery was driven by making use of the Voodoo ideas to try to solve other Monarch user’s practical problems – as presented on the Datawatch forums where a body of reference examples can still be found.
As I understand it the concepts were subsequently included in the Advanced level of the Monarch Training course.
Interestingly it seems that there are many report formats that benefit from the ‘Guru Trap’ approach, to the extent that this somewhat unusual need can become a requirement for a successful first Monarch project for a number of new Monarch users. This worries me a little because to dive in to the less self-evident functionality without a solid grounding on the basics may mean that people see their subsequent work in a more complicated light than is really necessary. It would be a shame if they were put off wider Monarch use by what they thought of as a complex and difficult to understand application when in reality the majority of tasks are likely to be much easier.
Maybe the time is right, now the method seems to have a proven track record, for a more complete documentation of the concept with several diverse examples to help with understanding.
But in the meantime I would still encourage people when faced with a specially challenging report to look at all the tools that Monarch offers and then try different ones in different ways to see what they can give. Even if they don’t work as you hoped that information is still usefully added to your personal knowledge base and skill set and will provide guidance for future Monarch based work.
Thanks for the prompt to revisit this subject.
Grant