Auto Number in QV

download Auto Number in QV

of 3

Transcript of Auto Number in QV

  • 8/10/2019 Auto Number in QV

    1/3

    Today lets 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? Its 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

    http://qlikviewnotes.blogspot.com/2010/01/best-way-to-count-keys-dont.htmlhttp://qlikviewnotes.blogspot.com/2010/01/best-way-to-count-keys-dont.htmlhttp://1.bp.blogspot.com/-KHB-XFVdEQA/Uiav9Tn_-DI/AAAAAAAAADI/mAYaG24Bd4o/s1600/TableModel1.JPGhttp://qlikviewnotes.blogspot.com/2010/01/best-way-to-count-keys-dont.html
  • 8/10/2019 Auto Number in QV

    2/3

    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 ShowSystem Fieldsis 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 inthe LOAD of the OrderHeader table. Our data model now looks like this:

    http://4.bp.blogspot.com/-PVfNquqsnPc/Uia1qxiznJI/AAAAAAAAADY/Z17eXxMh54A/s1600/TableModel2.JPG
  • 8/10/2019 Auto Number in QV

    3/3

    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 % keyfields! 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.htmland

    http://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bit-

    stuffed-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/

    http://qlikviewnotes.blogspot.com/2008/05/memory-sizes-for-data-types.htmlhttp://qlikviewnotes.blogspot.com/2008/05/memory-sizes-for-data-types.htmlhttp://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bit-stuffed-pointershttp://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bit-stuffed-pointershttp://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bit-stuffed-pointershttp://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bit-stuffed-pointershttp://community.qlikview.com/blogs/qlikviewdesignblog/2012/11/20/symbol-tables-and-bit-stuffed-pointershttp://qlikviewnotes.blogspot.com/2008/05/memory-sizes-for-data-types.html