Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Dynamic Sorting in the Script

Hello All,

I'm don't know if QlikView can solve this problem, but any guidance would be great.

I have a table that looks like this:

field1        field2

AAAZZZ
AAAYYY
AAAXXX
BBBWWW
BBBVVV
BBBUUU
BBBTTT
CCCSSS
CCCRRR
CCCQQQ
CCCPPP
CCCOOO
CCCNNN
CCCMMM
CCCLLL
CCC

KKK

I need logic that dynamically ranks so that it looks like this:

field1        field2          rank

AAAZZZ1
AAAYYY2
AAAXXX3
BBBWWW1
BBBVVV2
BBBUUU3
BBBTTT4
CCCSSS1
CCCRRR2
CCCQQQ3
CCCPPP4
CCCOOO5
CCCNNN6
CCCMMM7
CCCLLL8
CCCKKK9

I can guarantee sort order of field1 and field2.  The business needs dictate that this must happen in the script.

Any suggestions?

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

If the field2 is already sorted in the rank they should be as it seems to be the case here - this script should do:

2015-10-31 #1.PNG

The AutoNumber with the second parameter given to separate the groups of field1 will count a sequence independently resulting in the Rank you seem to need...

Resulting in this:

2015-10-31 #2.PNG

View solution in original post

3 Replies
roger_stone
Creator III
Creator III

You'll need to use Peek() in your script.

Something along the lines of

IF (Peek('field1')=[field1], Peek('fieldctr')+1, 1) as fieldctr

fieldctr gets reset to 1 every time field1 changes.

Hope that helps.

petter
Partner - Champion III
Partner - Champion III

If the field2 is already sorted in the rank they should be as it seems to be the case here - this script should do:

2015-10-31 #1.PNG

The AutoNumber with the second parameter given to separate the groups of field1 will count a sequence independently resulting in the Rank you seem to need...

Resulting in this:

2015-10-31 #2.PNG

Not applicable
Author

Works like a charm.  Thanks