Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
ArjunChandra
Contributor II
Contributor II

Want to Assign A Sequence Number from Bottom to Up for a Filed in Another field

A big Hi to All,

I Have a Table having Month, Year fields. I want to create a New field (Month Number) which should have row numbers of Month Values. Row number should start from last value of month as shown in the picture.

if any new value added to month like' May ,2020',   1 should be assigned to May 2020

I hope you guys got my point. Thanks for whoever  spending their time on it. if any of you guys did it, please reply me.

Output Table:

Screenshot (29).png

2 Solutions

Accepted Solutions
tresesco
MVP
MVP

Try like:

t1:
LOAD Month(Date#(Month, 'MMM')) as Month, 
     Year
FROM
[AutoSeqNum.xlsx]
(ooxml, embedded labels, table is Sheet1);

NoConcatenate
t2:
LOAD * , RowNo() as MonthNumber Resident t1 order by Year desc, Month desc; 

Drop Table t1;

View solution in original post

Vegar
MVP
MVP

@ArjunChandra If you have one row per month and year in your actual source data then @tresesco solution will do the trick. However if you do have duplicate rows with the same year-month combination it will get you in trouble.  

Consider the excel screenshot below

Vegar_0-1587979015210.png

 

To handle this issue you could use one of Qliks Autonumber functions such as autonumberhash128() instead of rowno() like this.

t1:
LOAD 
  Month(Date#(Month, 'MMM')) as Month, 
  Year
FROM
  [AutoSeqNum.xlsx] (ooxml, embedded labels, table is Sheet1);

t2:
LOAD 
  * , 
  RowNo() as MonthNumber1,  //Tresescos solution above
  AutoNumberHash128(Year,Month) as MonthNumber2 //Alternative solution
Resident t1 
order by 
  Year desc, 
  Month desc; 

Drop table t1;

 

View solution in original post

3 Replies
tresesco
MVP
MVP

Try like:

t1:
LOAD Month(Date#(Month, 'MMM')) as Month, 
     Year
FROM
[AutoSeqNum.xlsx]
(ooxml, embedded labels, table is Sheet1);

NoConcatenate
t2:
LOAD * , RowNo() as MonthNumber Resident t1 order by Year desc, Month desc; 

Drop Table t1;
Vegar
MVP
MVP

@ArjunChandra If you have one row per month and year in your actual source data then @tresesco solution will do the trick. However if you do have duplicate rows with the same year-month combination it will get you in trouble.  

Consider the excel screenshot below

Vegar_0-1587979015210.png

 

To handle this issue you could use one of Qliks Autonumber functions such as autonumberhash128() instead of rowno() like this.

t1:
LOAD 
  Month(Date#(Month, 'MMM')) as Month, 
  Year
FROM
  [AutoSeqNum.xlsx] (ooxml, embedded labels, table is Sheet1);

t2:
LOAD 
  * , 
  RowNo() as MonthNumber1,  //Tresescos solution above
  AutoNumberHash128(Year,Month) as MonthNumber2 //Alternative solution
Resident t1 
order by 
  Year desc, 
  Month desc; 

Drop table t1;

 

ArjunChandra
Contributor II
Contributor II
Author

Really Thanks for your help @tresesco , @Vegar