Auto Number in QV

Share Embed Donate


Short Description

Download Auto Number in QV...

Description

Today let‟s reinforce some QV data model principles for us old timers and introduce a few tricks for newbies to Qlikview. #1. Keys are not data. Key Fields in a Qlikview model should serve the data modeler, and not be used by chart Designers as data. Consider two tables, OrderHeader (one row for each Order) and OrderDetails (one row for each Order Line). linked together by Field OrderID.

OrderID may be a value that you need to display in your charts. However, problems arise when you try to do things like count(OrderID). Which end of the connection should the expression count? It‟s unreliable as discussed in detail here: http://qlikviewnotes.blogspot.com/2010/01/best-way-to-count-keys-dont.html The solution is to create a counter field on the table that represents the correct cardinality for the counter. If we are counting Orders, that would be the OrderHeader table. In the LOAD of the OrderHeader table: 1 as OrderCounter

Part two of of the recommendation is to isolate the key field so it is not mistakenly used as a data field. We do this by prefixing the key field name with a special character and SETing the QV system variable “HidePrefix” to that character. SET HidePrefix=’%’; In the LOAD of both OrderHeader and OrderDetails: OrderID as %OrderID Fields that begin with the HidePrefix value will not show up in: - Current Selections. - Dimension or Expression property dialog (unless “Show System Fields” is checked). Of course, the specific values of OrderID may be useful to display in UI charts. In that case we must preserve it as a data item in one and only one table. We will include it in the LOAD of the OrderHeader table. Our data model now looks like this:

OrderID is available as a data field, but appropriately only from the OrderHeader table. OrderCounter is now available as a field such that =sum(OrderCounter) will yield the correct Order count. Now we (the Data Modelers!) own those “%” key fields! They are ours, we told the UI designers explicitly that “it is not data” . Part three, and a very important part indeed, is to autonumber() the key fields. Autonumber() is a Qlikview lookup function that translates parameter values into integers. The sequential integers returned by autonumber() will reduce the RAM requirements and increase the linkage efficiency as detailed here http://qlikviewnotes.blogspot.com/2008/05/memory-sizes-for-data-types.html and http://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bitstuffed-pointers Admittedly, it gets a bit geeky. Bottom line, here is what you want to do for your keys: autonumber(OrderID, ‘%OrderID’) as %OrderID The autonumber() function converts values to sequential integers. The second parameter, „%OrderID‟, is important if you have multiple keys being autonumber() in your script. To summarize: #1. Keys are not data. #2, Isolate keys using the “SET HidePrefix=x;” variable. Establish counter fields on the appropriate table. #3. Use the Autonumber() function to convert key field values to sequential integers. This will minimize the memory footprint of the application and improve the efficiency of cross table look-ups. http://qlikviewcookbook.com/2013/09/autonumber-key-fields-and-sequential-integer-optimization/

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF