So I have a data which is in the following format:
Order ID | Order Date | Order Qty | Threshold Qty | Cummulative Sum |
---|---|---|---|---|
1 | Day1 | 5 | 9 | 5 |
2 | Day2 | 5 | 9 | 10 |
3 | Day3 | 6 | 9 | 16 |
I want to create a new column called "Threshold Date", which should contain the value:
Threshold Date |
---|
Null |
Day2 |
Day2 |
Which comes from the relation that it will be the first date when the net Cumulative Sum
goes over the Threshold Qty
. This function can be implemented in Python easily by taking a variable which holds the fixed value.
Is there any Qlik Sense function or method in which can be helpful to solve the following problem? I am relatively new to Qlik Sense.
The script below should give you the expected result (check out the screenshot).
One way to solve this is to check for each row:
Threshold Date
1 is null
2
Threshold Date
Cummulative Sum
is greater than the current value of Threshold Qty
true
then return the current value of Order Date
false
return null
1 is possible to reference new field while creating the new field but only in the context of its previous value. Thats why peek([Threshold Date])
can be used while [Threshold Date]
is being created (aka not loaded from a previous table)
2 In Qlik (Sense and View) -1
is true
and 0
is false
. More info here.
3 More about peek()
function here.
Load
*,
if(
IsNull(peek([Threshold Date])) = 0,
peek([Threshold Date]),
if(
[Cummulative Sum] > [Threshold Qty],
[Order Date],
null())
) as [Threshold Date]
;
Load * Inline [
Order ID, Order Date, Order Qty, Threshold Qty, Cummulative Sum
1 , Day1 , 5 , 9 , 5
2 , Day2 , 5 , 9 , 10
3 , Day3 , 6 , 9 , 16
];