Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikviewwizard
Master II
Master II

expression in script - Meaning

Hi All,

What is the meaning of the expression in script?

Thanks in advance.

if(KEY = previous(KEY), Rangesum(Quantity, peek(CumulSales)), Quantity) as CumulSales,

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Check with below example

KEY , Quantity

1, 10

1, 20

1, 15

2, 5

2, 4

LOAD

*,

If(KEY = previous(KEY), Rangesum(Quantity, peek(CumulSales)), Quantity) as CumulSales

FROM DataSource

ORDER BY KEY;

The output of above script

KEY , Quantity, CumulSales

1, 10, 10

1, 20, 30   (10 +20)  (Since previous key is 1 = Current key 1)

1, 15, 45   (30 + 15)  (Since previous key is 1 = Current key 1) Peek(CumuSales)  = 30

2, 5, 5     (5) (Here the Previous Key is 1 <> Current Key 2) So gettting only current quantity.

2, 4, 9    (5+ 4)  (Since previous key is 2 = Current key 2) Peek(CumuSales)  = 5

Hope this helps you.

Regards,

Jagan.

View solution in original post

3 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

Previous() will return the value of the given column in the previous row, in the script we are calculating the Cumulative sales based on the key.

If previous key value and the current key value is same then we are doing the sum of those values, otherwise we are starting the calculation again with the Current Quantity.

Hope this helps you.

Regards,

Jagan.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Check with below example

KEY , Quantity

1, 10

1, 20

1, 15

2, 5

2, 4

LOAD

*,

If(KEY = previous(KEY), Rangesum(Quantity, peek(CumulSales)), Quantity) as CumulSales

FROM DataSource

ORDER BY KEY;

The output of above script

KEY , Quantity, CumulSales

1, 10, 10

1, 20, 30   (10 +20)  (Since previous key is 1 = Current key 1)

1, 15, 45   (30 + 15)  (Since previous key is 1 = Current key 1) Peek(CumuSales)  = 30

2, 5, 5     (5) (Here the Previous Key is 1 <> Current Key 2) So gettting only current quantity.

2, 4, 9    (5+ 4)  (Since previous key is 2 = Current key 2) Peek(CumuSales)  = 5

Hope this helps you.

Regards,

Jagan.

qlikviewwizard
Master II
Master II
Author

Hi jagan,

I got it. Thank you so much for the detailed explanation.