Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculate price variation

Hi I need to do something very simple, I have to calculate a price variation during the year..

I have:

     price1

     price2

     price3

     price4

     price5

     price6

     price7

And I want: (price2-price1)/price1

     ..(price3-price2)/price2....

     (price4-price3)/price3 and so on....

How can I do that in a table? I tried to to the ratio but It doesn't show any value!

6 Replies
Gysbert_Wassenaar

Are those different fields in a table or values in one field? If they are values in one field you can try using the above() function. For example with a table that contains a Date field and a Price field you could create a straight table with Date as dimension and use Price/above(Price) - 1 as expression.


talk is cheap, supply exceeds demand
Not applicable
Author

Are different field in a table

Gysbert_Wassenaar

Then you need a different expression for each variation calculation:

Expression1: Price2/Price1 -1

Expression2: Price3/Price2 -1

...etc


talk is cheap, supply exceeds demand
nagaiank
Specialist III
Specialist III

Does the following script give a clue to solve your problem?

Data:

LOAD RowNo() as ID, * Inline [

Price

10

11

12

13

14

15

13

11

];

Final:

NoConcatenate

LOAD ID,Price,

If(IsNull(Peek('Price')),Null(),(Price-Peek('Price'))/Peek('Price')) as Ratio

Resident Data Order By ID;

DROP Table Data;

Not applicable
Author

I'm trying to do that but It doesn't shows any value just an hyphen!

Gysbert_Wassenaar

Can you post an example document that demonstrates the problem?


talk is cheap, supply exceeds demand