Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
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?

Tags (1)
1 Solution

Accepted Solutions
MVP
MVP

Re: Dynamic Sorting in the Script

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

3 Replies
roger_stone
Contributor III

Re: Dynamic Sorting in the Script

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.

MVP
MVP

Re: Dynamic Sorting in the Script

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

Re: Dynamic Sorting in the Script

Works like a charm.  Thanks

Community Browser