Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
waleeed_mahmood
Creator
Creator

Assigning rows a unique ID

Hi everyone,

I have a Qlik related problem i cant seem find any help on.

I have a Table called Table A. It has around 20 columns and 26000 rows. From that table i extract a new table with the fields i need, as shown below:

table1.JPG

To extract the above table from Table A, i used the following Script:

 

 

load
    Distinct("F MPG") as MPG,
    EFlag as ef,
    RFlag as rf,
    [SAP Material] as SAPM,
    "C L2 NP" as L2,
    "F MC" as MC,
    Owner as owner,
    '0%' as "Planned Change",
    FSIML2NP as FSIM
Resident Material_Master_Table;

 

 

What i want to do, is assign a row number (1-to-n) for all the rows in my extracted table. From my experiments, i cant seem to use Rowno() or RecNo() becuase i am using DISTINCT in my extract script as shown above. So, if i were to use RowNo()/RecNo() it would make no sense. Even if i wasnt using distinct in my script, i still would not want to have the RowNo/RecNo from the original table. I have tried using AutoNumber(SAPM,FMPG) and few other variations of autonumber, but so far no luck.

About my fields:

For each MPG, there could be multiple MCs as shown above.

SAPM field has unique entry for each row (its a product number).

Multiple MPGs/MC can belong to one Owner.

L2 and FSIM are just numbers that i use in other calculations.

OUTPUT:

it would be similar to picture shown, except there would be an ID column which has unique number for each row of that table.

IDOwnerMPGMCPlannedChangeActual Change
10018AAS4....0..%
20018AAS4....0..%
30018AAS4....0..%
40018AAS4....0..%
50018AAS4....0..%

Note: I didnt type all the values, but this should give the output idea.

I'd really appreciate the help!!!!

Please let me know if you need more information.

Thank you.

Labels (4)
1 Solution

Accepted Solutions
Lisa_P
Employee
Employee

Try using Autonumber feature:

load
    Distinct("F MPG") as MPG,
    Autonumber("F MPG") as ID,
    EFlag as ef,
    RFlag as rf,
    [SAP Material] as SAPM,
    "C L2 NP" as L2,
    "F MC" as MC,
    Owner as owner,
    '0%' as "Planned Change",
    FSIML2NP as FSIM
Resident Material_Master_Table;

View solution in original post

2 Replies
Lisa_P
Employee
Employee

Try using Autonumber feature:

load
    Distinct("F MPG") as MPG,
    Autonumber("F MPG") as ID,
    EFlag as ef,
    RFlag as rf,
    [SAP Material] as SAPM,
    "C L2 NP" as L2,
    "F MC" as MC,
    Owner as owner,
    '0%' as "Planned Change",
    FSIML2NP as FSIM
Resident Material_Master_Table;
waleeed_mahmood
Creator
Creator
Author

Hi Lisa,

Thank you for your reply. I had to change "F MPG" in autonumber to "F MC" since F MPG isnt a unique value i believe. But, in the end it worked fine for me. 

Thank you for your help.