Skip to main content

App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save $300 before February 6: REGISTER NOW!
cancel
Showing results for 
Search instead for 
Did you mean: 
erric3210
Creator
Creator

Autonumber Function Issue

Hi Community,

Today I faced something strange issue with Qlik Sense which I'm not actually able to figure out whether it's a issue or I'm making some mistake.

I'm facing issue with Autonumber() function.

Version I'm using: November 2020 Patch 4

 

Scenario1: When I try to run below script then it executes in 1 minute.

Table1:
LOAD
Id
Id&'_'&Number AS Key
Date(InvoiceDate) AS New_Date,
Quantity,
Amount,
Number
FROM Invoive.qvd(qvd)
Where InvoiceDate >= Date(today()-240);

 

Scenario2: When I try to run below script then it executes in more than 1 hour.

                       I just made a small change in script as per the Best practice of Qlik Sense.

                       Instead of Id&'_'&Number AS key, I changed it to Autonumber(Id&'_'&Number) AS Key

Table2:
LOAD
Id
Autonumber(Id&'_'&Number) AS Key
Date(InvoiceDate) AS New_Date,
Quantity,
Amount,
Number
FROM Invoive.qvd(qvd)
Where InvoiceDate >= Date(today()-240);

 

Am I making any mistake using Autonumber function.

 

Please help so that I can fix the issue.

 

Regards,

Eric

Labels (1)
6 Replies
erric3210
Creator
Creator
Author

@MarcoWedel Thank You Sir for replying. The link you shared is great but I don't want to use Peek & previous in my code.

Is there a way with Autonumber().

Also, 1 more thing I've used used Autonumber() function in many of my Applications but this is the first time I've faced this issue. Do I need to change the Autonumber Script for all of them.

I tried the solution but it didn't work. Here is my testing:

AAA:
LOAD *, Recno() AS Rec_Id, AutoNumber(Customer_ID&'_'&Shipment_Id) AS Auto_Key INLINE [
Customer_ID, Shipment_Id, Amount
1111, 11-A, 1000
1111, 11-A, 2000
1112, 11-C, 3000
1113, 11-D, 4000
];

BBB:
NOCONCATENATE
LOAD *,
if (Previous(Customer_ID) = Customer_ID and Previous(Shipment_Id) = Shipment_Id, peek('Unique_Value') + 1, 1) as Unique_Value
Resident AAA
Order by Customer_ID, Rec_Id;
Drop Table AAA;

Wrong Result:

Error.PNG

 

Regards,

Eric

Lech_Miszkiewicz

Why don't you use Autonumber Command instead of function as shown in @Oleg_Troyansky post https://www.naturalsynergies.com/q-tip-21-autonumber-so-old-so-new-2/

?

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
erric3210
Creator
Creator
Author

Thanks @Lech_Miszkiewicz for sharing the Link.

I find it little tricky. Can you share  its example.

What I'm thinking it's better not to use Autonumber() and simply create a composite key using just field names.

It's safe & work 100%

 

Regards,

eric.

Lech_Miszkiewicz

what is the tricky part for you?

you just create normal composite keys as you currently do and at the very end of your script you just put command

Autonumber  Key; 

and thats it  - have you tried that?

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
oskartoivonen
Partner - Contributor III
Partner - Contributor III

Best practice with autonumber is precisely as @Lech_Miszkiewicz recommends, you use the autonumber command outside the LOAD-statement as the final thing you do before your data model is finished. That way it's also easy to deactivate if you need to access the content of your fields.