Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
Not applicable

Loop or geometric series

Quick question,

Is it better to use a loop to do the calculations or use the summation of geometric series?

Example:

5(1.02)+5(1.02)^2+5(1.02)^3 + ... + 5(1.02)^10

should I use a loop ? for i = 1 to 10

or use the geometric series summation  5(1.02) * ( 1- 1.02^10)/(1-1.02) ?

I don't want to use PV or FV

Thank you

5 Replies
ahaahaaha
Honored Contributor

Re: Loop or geometric series

Hi Akl,

If the calculation is performed for a small amount of data, I do not see any fundamental difference.

But in general it's just interesting, why do not you want to use functions PV or FV?

Regards,

Andrey

Not applicable

Re: Loop or geometric series

Hi Andrey,

What if the calculation is being performed or a large amount of data?

I am very new to qlik sense and that's why I am asking.

As for not using PV or FV functions, there isn't any reason. I will be using them in my codes but for this one specific script I don't want to use them because it would be easier to manipulate the whole equation using the summation or loop. (it is a specific case)

ahaahaaha
Honored Contributor

Re: Loop or geometric series

Like an idea, please see this files Yandex.Disk andYandex.Disk (for some reason they could not be attached here). In them, I tried to simulate the settlement process for your both options. For 10 million lines, the calculation the first option was a little faster.

You can replace the calculation in this model with another one and again measure the result by reloading the data. The number of downloadable records can be changed.

Just in case the script code of the first file

LET vStartLoop=Now();

Table1:

LOAD

RecNo() as LoopID,

5*1.02+5*Pow(1.02,2)+5*Pow(1.02,3)+5*Pow(1.02,4)+5*Pow(1.02,5)+5*Pow(1.02,6)+5*Pow(1.02,7)+5*Pow(1.02,8)+5*Pow(1.02,9)+5*Pow(1.02,10) as ValueLoop

AutoGenerate 10000000;

LET vFinishLoop=Now();

LET vTimeLoop=Time(vFinishLoop-vStartLoop);

Result

1.jpg

Tthe script code of the second file


LET vStartGeometric=Now();

Table2:

LOAD

RecNo() as GeometricID,

5*(1.02)*(1- Pow(1.02,10))/(1-1.02)  as ValueGeometric

AutoGenerate 10000000;

LET vFinishGeometric=Now();

LET vTimeGeometric=Time(vFinishGeometric-vStartGeometric);

Result

2.jpg

Regards,

Andrey

Not applicable

Re: Loop or geometric series

Thank you so much !

ahaahaaha
Honored Contributor

Re: Loop or geometric series

I'm glad if something could help you.