Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone & Happy Holidays,
I am relatively new to QlikView development, and have been told that a good exercise for all coding languages (even simple ones) is to solve some of Euler's problems.
For those unfamiliar with Project Euler, here is a link to the list of problems: https://projecteuler.net/archives
The first problem is quite simple: to find the sum of all of the numbers with multiples of 3 or 5 that are below 1000.
For my solution, I wanted my first step to generate a table consisting of the numbers 1 through 999, along with a flag that returned "1" if that number was divisible by either 3 or 5, and a "0" otherwise. But for some reason, this load statement returns nothing. No fields are even generated.
Set a=1;
Load
a + IterNo() As Number
,If(Mod(a + IterNo(),3)=0 OR Mod(a + IterNo(),5)=0,1,0) As DivisibleFlag
While a + IterNo() < 1000;
The second step in my solution would be to create a text box in the .qvw which simply had the following expression: =Sum({$<DivisibleFlag = 1>Number}
It seems like I'm making some basic mistake with syntax, but I haven't been able to find where I'm going wrong so far. Any help will be appreciated.
EDIT: Typo in link to Project Euler.
Try the below script
LOAD
a + IterNo() As Number
,If(Mod(a + IterNo(),3)=0 OR Mod(a + IterNo(),5)=0,1,0) As DivisibleFlag
While a + IterNo() - 1 < e;
LOAD * INLINE
[a,e
1,1000
];
Try the below script
LOAD
a + IterNo() As Number
,If(Mod(a + IterNo(),3)=0 OR Mod(a + IterNo(),5)=0,1,0) As DivisibleFlag
While a + IterNo() - 1 < e;
LOAD * INLINE
[a,e
1,1000
];
Thanks! This works. Can you possibly explain why your script works, and mine does not? The logic is almost identical, you're just drawing on your initial a value and your final e value by referencing an in-line table--and I don't see why that would work, but using set a = 1, would not.