Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I need to solve in a load from a result of a previous row.
I have the following problem:
I have a table with discount rates to apply:
Customer discount Percentage
1 1 25%
1 2 10%
1 3 15%
The drawback is that the discounts are concatenated, so that the results would be for a price of 100:
Customer discount Percentage
1 1 25% - 75
1 2 10% - 67.50
1 3 15% - 57.38
How can I solve it in a Qlik LOAD?
TESTDATA:
LOAD
*
INLINE
[Customer, Discount#, Discount, Amount
1, 1, 25%, 100
2, 1, 10%, 500
1, 2, 10%, 100
2, 2, 15%, 500
1, 3, 15%, 100
];
NOCONCATENATE LOAD
Customer,
Discount#,
Discount,
If( Discount# = 1 , (1-Discount)*Amount , (1-Discount)*Peek('Amount') ) AS Amount
RESIDENT
TESTDATA
ORDER BY
Customer, [Discount#];
DROP TABLE TESTDATA;
TESTDATA:
LOAD
*
INLINE
[Customer, Discount#, Discount, Amount
1, 1, 25%, 100
2, 1, 10%, 500
1, 2, 10%, 100
2, 2, 15%, 500
1, 3, 15%, 100
];
NOCONCATENATE LOAD
Customer,
Discount#,
Discount,
If( Discount# = 1 , (1-Discount)*Amount , (1-Discount)*Peek('Amount') ) AS Amount
RESIDENT
TESTDATA
ORDER BY
Customer, [Discount#];
DROP TABLE TESTDATA;