Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Compare data from the same field in the script

Due to some less than perfect management of our ERP system, I need to edit data loaded from the database in the script (it regards the received quantity on purchase orders).

When there have been several deliveries and thus several records made for the same order line, the registered quantity received gets messed up (in the database). However for every quantity registered there's a field where the quantity already invoiced is registered. By using the quantity invoiced for one data entry I can calculate the quantity actually received for another data entry.

In other words I need to compare values from the same field.

How can I do this in the script?

I need to compare all data for each order line and calculate new value and connect them to the right delivery.

This is the kind of logic I would need to implement (for every order line):

Load
OrderLineID

For i = 1 to count(QtyInvoiced)-1
if(Max(QtyReceived, i) > Min(QtyAlreadyInvoiced, i),
Min(QtyAlreadyInvoiced, i+1) - Min(QtyAlreadyInvoiced, i)) as QtyActualReceived,
OrderLineID + QtyInvoiced as OrderLineIDNew,
Resident OrderDetails
group by OrderLineID

Is it possible to do this in the script somehow?

1 Solution

Accepted Solutions
d_pranskus
Partner - Creator III
Partner - Creator III

Hi

Please find solution attached

Cheers

Darius

View solution in original post

7 Replies
d_pranskus
Partner - Creator III
Partner - Creator III

Hi

Could you attach sample application with demo data attached to a post?

Darius

Not applicable
Author

Hi

Here's some sample data:

OrderDetails:
LOAD * INLINE [
OrderLineID, QtyInvoiced, QtyRecieved
34879 10, 0, 19856
34879 10, 2354, 17502
34879 10, 14044, 5812
40710 10, 0, 20986
40710 10, 11012, 9911
40710 10, 20923, 63
];

I want to implement the following logic on this data:

For i = 1 to count(QtyInvoiced)-1
if(Max(QtyReceived, i) > Min(QtyAlreadyInvoiced, i),
Min(QtyAlreadyInvoiced, i+1) - Min(QtyAlreadyInvoiced, i)) as QtyActualReceived,
OrderLineID + QtyInvoiced as OrderLineIDNew,
Resident OrderDetails
group by OrderLineID

I want a resulting table with the following data:

OrderDetailsActual:
LOAD * INLINE [
OrderLineID, QtyInvoiced, QtyRecieved, QtyActualRecieved
34879 10, 0, 19856, 2354
34879 10, 2354, 17502, 11690
34879 10, 14044, 5812, 5812
40710 10, 0, 20986, 11012
40710 10, 11012, 9911, 9911
40710 10, 20923, 63, 63
];



d_pranskus
Partner - Creator III
Partner - Creator III

Could you explain BusinessLogic for this algorithm or business logic related to the data you provided:

For i = 1 to count(QtyInvoiced)-1
if(Max(QtyReceived, i) > Min(QtyAlreadyInvoiced, i),
Min(QtyAlreadyInvoiced, i+1) - Min(QtyAlreadyInvoiced, i)) as QtyActualReceived,
OrderLineID + QtyInvoiced as OrderLineIDNew,
Resident OrderDetails
group by OrderLineID

I need this because I don't have field QtyAlreadyInvoiced, And it would be easier for me to understand the logic.

Cheers

Darius


Not applicable
Author

Sorry, I made mistake, there's no QtyAlreadyInvoiced (they're all supposed to be QtyInvoiced

so it would look like following:

For i = 1 to count(QtyInvoiced)-1
if(Max(QtyReceived, i) > Min(QtyInvoiced, i),
Min(QtyInvoiced, i+1) - Min(QtyInvoiced, i)) as QtyActualReceived,
OrderLineID + QtyInvoiced as OrderLineIDNew,

Thanks!

d_pranskus
Partner - Creator III
Partner - Creator III

Hi

Please find solution attached

Cheers

Darius

Not applicable
Author

Thank you very much for all your help!!!

It seems to work great now!

Thanks,
Rickard

d_pranskus
Partner - Creator III
Partner - Creator III

Hi

If so, could you confirm the answer, please, to close the issue. Thanks.

Cheers,

Darius