Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

brianrmacdonald
Contributor

Strange problem with script

Here is a snippet of a script that I am working on:

DataRaw:

LOAD * Inline [

path, path_count

'String1',2

'String2',1

'String3',1

'String4',2

'String5',1

'String6',1

];

Let numRows = NoOfRows('DataRaw');

For myRow = 1 to NoOfRows('DataRaw')

  Let vFld = FieldValue('path',myRow);

    Let vCount = FieldValue('path_count',myRow);

    Let myPlace = 1;

Next myRow

The first two rows of the data process just fine but I am getting Null for the value of vCount at the third row and every row after that.  Here is my debug output.

2017-04-03_17-27-58.jpg

What am I doing wrong?

1 Solution

Accepted Solutions
craigsutton
Contributor

Re: Strange problem with script

I got the same result.  What about using Peek?  I had better luck with Peek.

DataRaw:
LOAD * Inline [
path, path_count
'String1',2
'String2',1
'String3',1
'String4',2
'String5',1
'String6',1
]
;


Let numRows = NoOfRows('DataRaw');

For myRow = 0 to (NoOfRows('DataRaw')-1)
Let vFld = Peek('path', myRow, 'DataRaw');
// Let vFld = FieldValue('path',myRow);
Let vCount = Peek('path_count', myRow, 'DataRaw');
// Let vCount = FieldValue('path_count',myRow);

Let myPlace = 1;

Next myRow

3 Replies
craigsutton
Contributor

Re: Strange problem with script

I got the same result.  What about using Peek?  I had better luck with Peek.

DataRaw:
LOAD * Inline [
path, path_count
'String1',2
'String2',1
'String3',1
'String4',2
'String5',1
'String6',1
]
;


Let numRows = NoOfRows('DataRaw');

For myRow = 0 to (NoOfRows('DataRaw')-1)
Let vFld = Peek('path', myRow, 'DataRaw');
// Let vFld = FieldValue('path',myRow);
Let vCount = Peek('path_count', myRow, 'DataRaw');
// Let vCount = FieldValue('path_count',myRow);

Let myPlace = 1;

Next myRow

brianrmacdonald
Contributor

Re: Strange problem with script

Well after much hair pulling the solution seemed to be to use the Peek function instead of FieldValue and also specify the table name.  Additionally the first record for use with Peek is record 0.

So the script should look like this...

For myRow = 0 to NoOfRows('DataRaw')-1

  Let vFld = Peek('path',myRow,'DataRaw');

    Let vCount = Peek('path_count',myRow,'DataRaw');

    Let myPlace = 1;

Next myRow

brianrmacdonald
Contributor

Re: Strange problem with script

We were typing at the same time.  I'll mark yours as correct.