Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
HI all
Could any one tell me how to calculate the GCD of the two field values in qlikview..
for ex:
I have field A and B like
A B
10 20
6 9
20 11
the output should be come as like
A B GCD
10 20 10
6 9 3
20 11 1
hope it will give clear understanding
Could anyone help me...
thanks in advance
The method is the Euclidean Algorithm and the code is way beyond me. This is a representation of the code in C. Macro guy needed
http://en.literateprograms.org/Special:Downloadcode/Euclidean_algorithm_%28C%29
This is the code breakdown explanation
Hi,
Below is a simplification of the calculation of GCD.
"I'll explain the algorithm with an example. Let's find the gcd of
210 and 990.
Divide 990 by 210: quotient 4, remainder 150; ignore quotient
Divide divisor from previous step by remainder from previous step
divide 210 by 150: quotient 1, remainder 60; ignore quotient
Divide divisor from previous step by remainder from previous step
divide 150 by 60: quotient 2, remainder 30; ignore quotient
Divide divisor from previous step by remainder from previous step
divide 60 by 30: quotient 2, remainder 0.
When the remainder becomes 0, as it always will, then go to the
previous step and choose the remainder, in this case 30. This is the
gcd! Neat!"
Using MOD(x1,x2) is probably the way to go with this.
Hi, taking the idea from here http://en.wikipedia.org/wiki/Euclidean_algorithm i've made this
1st: Create a Function in the macro editor
function gcd(a, b)
while b <> 0
t = b
b = a mod b
a = t
wend
gcd = a
end function
then, use it in the script
DATA:
LOAD
F1,
F2,
gcd(F1,F2) as GCD
INLINE [
F1, F2
10,20
6, 9
20,11
4,3
];
And the result is
F1 F2 GCD
10 20 10
6 9 3
4 3 1
20 11 1
4 2 2
Rgds
This is helpful.
I have a different datamodel where columns are shown as rows (attached).
Is it possible to calculate the GCD based on this model ?
I need to show the ratio between Designers vs Layout and vice-versa. In order to get the ratio, we need to get the GCD first.
Project Skills Month Headcount ProjectA Designers 1-Oct-11 6.25 ProjectA Layout 1-Oct-11 0.50 ProjectB Designers 1-Nov-11 5.50 ProjectB Layout 1-Nov-11 1.50
Hi Anthony,
You can do this. But for this you need to get designers and Layout as columns. Please load table with where clause Skills =Designers and name headcount as Designer Headcount and then Join it with same table on where clause Skills= Layout and Head count as Layout Headcount on Primary key (May be Project and Month) and use the above defined function.
Hope this will help.
Regards
VIjay