Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
pepe2209
Creator
Creator

Create ascending count variable

Hello

please look at the example:

MaingroupSubgroupDateX
1A11
1

B

21
1C31
1C42
2A51
2A62
2A73
2B81
3A91
3B101
3B112
3B123
3C131

I want to add variable X to a qvd which contains Maingroup, Subgroup and Date (Ordered by Maingroup asc, Subgroup asc, Date asc).

The rule for X is that it should count up as long as the values for maingroup and subgroup are the same.

How can I achieve this the best possible way?

your help would be much appreciated.

regards,

Peter

1 Solution

Accepted Solutions
Gysbert_Wassenaar

MyTable

load Maingroup, Subgroup, Date,

if(Maingroup = previous(Maingroup) and Subgroup=previous(Subgroup), 1+peek(X), 1) as X

from myqvdfile.qvd (qvd);


talk is cheap, supply exceeds demand

View solution in original post

3 Replies
Gysbert_Wassenaar

MyTable

load Maingroup, Subgroup, Date,

if(Maingroup = previous(Maingroup) and Subgroup=previous(Subgroup), 1+peek(X), 1) as X

from myqvdfile.qvd (qvd);


talk is cheap, supply exceeds demand
ashfaq_haseeb
Champion III
Champion III

H, look at the attached application

code:

Temp:

load * , Maingroup & Subgroup as Key;

LOAD Maingroup,

     Subgroup,

     Date

     //X

FROM

[http://community.qlik.com/thread/122241]

(html, codepage is 1252, embedded labels, table is @1);

Main:

Load

  *,

  IF(Key = Previous(Key), Peek('X')+1, 1) as X

Resident Temp

Order By Maingroup, Subgroup,Date;

Drop Table Temp;

Regards

ASHFAQ

tresesco
MVP
MVP

Temp:
LOAD Maingroup,
     Subgroup,
     Date
     //X
FROM
[http://community.qlik.com/thread/122241]
(html, codepage is 1252, embedded labels, table is @1);

NoConcatenate
Final:
Load
*,
If(Maingroup=Peek('Maingroup') and Subgroup =Peek('Subgroup'), Peek('X')+1,1) as X
Resident Temp Order By  Maingroup,Subgroup,Date;

Drop table Temp;