Skip to main content
hic
Former Employee
Former Employee

There are several good reasons not to use macros in QlikView.

 

First of all, macros are run using Microsoft COM Automation. They will run client-side and work fine if you use the Desktop or the IE PlugIn, which both are Windows executables. But if you use the Ajax client, there are severe limitations since the macros now need to run on the server instead of on the client. For a server, there are both technical limitations and security implications that have forced us to restrict the capabilities of macros.

 

So, if you want to use the Ajax client, you should avoid macros.

 

Trigger.png

 

Secondly, a common beginner’s mistake is to use macros to build logic into QlikView; logic that almost always works better if QlikView’s own out-of-the-box functionality is used.  An example is assigning a value to a variable every time a selection is made: In other tools you would use a trigger and a macro, but in QlikView this is not needed: You should instead define your variable using an equals sign and the appropriate expression.

 

Further, many problems can be solved by using a smart data model instead of macros.

 

Macros often confuse the user. A user wants a predictable behavior and macros often do exactly the opposite: They create behaviors that exist in some places but not in other. This is counter-intuitive.

 

Finally, if the macro is long or complex, it will often push QlikView into an unstable situation. We have often seen this in documents sent to our support organization. The reason is probably a poor fit between the synchronous, sequential execution of a macro and QlikView’s internal asynchronous, multi-threaded computation.

 

From a development perspective, the macro feature is a secondary functionality. In the development process, it will rarely get first priority when compared to the “native” functionality: I.e. in the choice between keeping macro functionality unchanged and improving the out-of-the-box functionality, the QlikView development team will often choose the latter. This means that you can get a changed macro behavior when you upgrade your QlikView installation.

 

Macro1.png

 

Some facts around macros:

 

  • Single-Threaded?
    Macros are in their nature sequential – i.e. in a way single-threaded. But this is not the same as saying that all calculations started by macros are single-threaded. For instance, if a macro makes a selection that causes a chart to be calculated, both the logical inference and the chart calculation are multi-threaded. As they should be.
  • Clears cache?
    No. A macro does not clear the cache. (Unless you use the macro in the picture above...)
  • Clears the Back-Forward stack?
    No. A macro does not clear the Back-Forward stack.
  • Clears the Undo-Redo stack?
    Yes, if the macro contains layout changes, the Undo-Redo stack will be cleared.

 

So, I strongly recommend you don't use macros, unless it is in a Desktop environment. And there they should be short and concise! On a server you should instead use Actions.

 

There is however one thing that may confuse the user more than macros. And that is Triggers. If a macro or an action is started from a nicely labeled button, then the user will understand what happens.

 

But if the macro instead is triggered by some other event, e.g. the changing of a variable value, we have a very different situation. Then you will most likely create a non-intuitive behavior.

 

Macros are Bad, but Triggers are Worse.

 

HIC

 

See also

The Key to Heaven

56 Comments
sudeepkm
Specialist III
Specialist III

Hi Henric,

     Thanks a lot for sharing an insight on macros. We are not allowing our developers to use macro in our environment as we are using AJAX mode for our client access.

     However sometimes our clients demand certain features which are possible only using macros. We face a lot of difficulty in explaining our clients about the feature not being native to the product.

As an example :

QlikView has a Trigger Action type as "Print Object" which works fine in AJAX mode however similar feature "Print Sheet" is not supported in AJAX client. This puts us in a situation where we cannot provide satisfactory answers to our clients that why the Print Sheet does not work whereas a similar feature Print Object works fine in AJAX mode.

macros-are-bad.png

Another feature which our clients would like to see is the export to xls for multiple tables to multiple sheets of same xls output. (This is possible only using Macro).

Are there any plans for taking care of such UI utility type features in future. Please suggest. Thanks in advance.

Thanks and Regards,

Sudeep

2,985 Views
Not applicable

Hi Henric, Sudeep,

Thanks for the interesting text and comments above. To follow up on Sudeep's comments - when it comes to exporting charts/tables to Excel and Power Point QV simply does not have a good answer. The best indication for this is the extent of the online discussions around these topics in the QV community. The only way around this limitations is using Macros. I'm curious to hear Henric's thoughts on this particular point.

Thanks and Rgds,

Ami

0 Likes
2,985 Views
brian_booden
Partner Ambassador
Partner Ambassador

I think it's fair comment that QlikView does not handle exporting very well in terms of formatted output in Excel specifically.  Of course, export to Excel is possible and easy enough, but if you want flexibility in terms of formatting, then it does either need to be macros or a 3rd party tool such as NPrinting or Report Manager.

It would interesting to hear from Qlik though, as to whether report formatting and output is something they are concerned with internally, or whether they will lean on existing solutions such as the above to provide the capability needed.

0 Likes
3,023 Views
pover
Luminary Alumni
Luminary Alumni

I have a customer that battled with macros to export multiple reports to Excel.  Once they found out about NPrinting and implemented it, they disabled all the macros and were much happier.  There are other tools out export tools out there and I don't think Qlik should invest time and resources in reporting.  I would rather see a QlikView.Next jammed pack with more innovative features that spread information in other more effective ways than an Excel spreadsheet.

3,023 Views
IAMDV
Luminary Alumni
Luminary Alumni

Thank you HIC. Nice post on Macros.

A Macro does what you tell it to do, not what you want it to do.

Cheers,

DV

3,023 Views
Not applicable

Oh, geez.. this reminds me of Djikstra's "GOTO Considered Harmful". Sweeping generalizations sweep a lot under the rug.

My firm uses a product "Goldmine" to track activity by sales and customer service. It puts a timestamp on each record of DD/MM/YY hh:mm, which is fine, but there are times when quick users can put two, sometimes three, entries in the same minute. When I ask QV to list out these activities with the time stamp, as you might imagine, I get "null" as a result. I had to find a way to get the seconds added to the time stamp.

Goldmine does encode the creation time, down to the second, in its "RECORDID" field. Here is the code in my macro: (note: the algorithm is GM's; I just reversed it)

Function secs(recid)

For I = 1 to 6

   Dummy = mid(recid,I,1)

   If Isnumeric(Dummy) THEN

         CharASCVal = ASC(Dummy) - 55

   Else

         CharASCVal = ASC(Dummy) - 48

   END IF

   CharVal = CharASCVal * 36 ^(7-i)     <- yes, that's an exponent

  DecryptDate = DecryptDate + CharVal

Next

FirstSec = DecryptDate/50 MOD 60

If FirstSec< 10 then

    secs = "0" + cstr(FirstSec)

ELSE

     secs = cstr(FirstSec)

END IF

END FUNCTION

I put this function in my load statement, and make a full time stamp from:

LOAD

     DATE#(Date(OnDate+OnTime,'MM/DD/YY hh:mm') & Secs(RECORDID),'MM/DD/YY hh:mm:Ss') As FullTime

This gets used in dozens of different QV files. If you can find a more efficient and time saving method of doing this rather than using a macro, I'd like to hear it. I always thought the entire purpose of functions and subroutines was to break code down into small, robust units. Since I'm unaware of any ability to do this in QV scripts, I'll continue to use macros where warranted.

However, I do agree with someone above - we tried exporting files with macros. When we switched to nPrinting, that all stopped, and the users are much happier.

0 Likes
3,023 Views
barryharmsen
Luminary Alumni
Luminary Alumni

I think macros are bad when used in user-facing applications. During development, I think macros are great!

I'm a lazy person (though when I'm speaking with clients I rephrase it as "efficient" ) and I dislike repetitive work. That is why I love to use macros (and subroutines) during development to automate frequently occurring tasks that require a lot of manual work.

One such example is the "ad-hoc analysis" object, the one where you pick your dimensions and measures from a list and the result is shown in a straight table/pivot table/etc. My clients love those, but they are IMHO a real hassle to build. Typing in dozens of show/hide conditions takes a long time and is mind-numbing. So, I created a macro that does it for me. The client wants to change something? Just delete the object and regenerate it.

Of course, this requires a little more effort upfront and it doesn't make sense for every task, but I generally find that the time-savings well outweigh the initial time investment.

Regarding NPrinting, I absolutely love the product, but (as I understood it) they're using the same methods/type library to export data from QlikView. Instead of using your own macros you're just using someone else's. At their pricing it is still a great deal though, and IMHO having someone else build your tools is an even more "lazy" approach, so that definitely gets my approval

3,023 Views
hic
Former Employee
Former Employee

@ Barry Harmsen We are basically saying the same thing... Note the "...unless it is in a Desktop environment" in my post. Yes, I use macros too, but just as you say - they are bad in user-facing applications.

@ Kevin Bertsch No, I do not see these views as sweeping generalizations. Macros imply a number of drawbacks and problems, some of which I mention. But of course they have advantages too. Barry makes a good point when he points out the time-saving aspect in the development phase. And as always, you need to weigh pros and cons. The purpose of the blog post was to make people aware of the drawbacks of macros.

(...and I bet you I can write that macro function of yours using native QlikView functions only.  )

@ Brian Booden Concerning reports and NPrinting: Yes, we are concerned, but the way we see it is that reporting is better done by our partners than by us. So we welcome partners like NPrinting. (NPrinting, by the way, uses our COM automation interface in our OCX module. In other words: From a code perspective a single user, using something equivalent to the Desktop. Which I think is OK.)

HIC

0 Likes
3,023 Views
Not applicable

Henric,

I have no doubt you can ‘recreate’ the function. (My knowledge of QV is a mere evanescent shimmer

on my cerebral cortex compared to yours. )

Now, recreate it every time in two dozen different QV files, then,

when the function changes for any reason, go back and maintain it.

I stand by my earlier assertion: breaking code down into robust, re-usable chunks is good practice.

If QV had any type of user defined function/sub-routine in its scripting tool, I wouldn’t need the

macro, but AFAIK, it doesn’t.

Cheers,

Kevin Bertsch

Data Analysis and Reporting

Ecustoms

0 Likes
2,999 Views
hic
Former Employee
Former Employee

I totally agree both with your view on "robust and re-usable chunks" and the need for user defined functions. Further, most my arguments against macros pertain to "user-facing" situations, as Barry put it. And your example isn't user-facing...

So, bottom line: There are drawbacks. Be aware of them. Then use macros where appropriate.

HIC

0 Likes
2,999 Views