Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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:
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;
@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
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;
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;
@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
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;