Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
timmarsh
Contributor III
Contributor III

Help with skipping an i in a for loop (or moving to next i) with If statement

Hi all,

I am trying to integrate to Google Maps. Whilst I've managed to do that, I need to handle records where there is no address. Some records do not have an address as I've mashed all the FACTS into one.

What I am doing is peeking inside a field, and, if it's null, I want to move to the next i in the for loop.

If there's an address, then move to the table.

I've mucked around with a few options but none seem to work.

Be gentle, I'm just a beginner.

Here's what I have: what I end up with is a GMAP call that fails as address is often null.

let noRows = NoOfRows('Facts')-1;

for i=1 to $(noRows)

//let a=peek('Pt_FNAME',$(i),'Facts');

//let b=peek('Pt_LNAME',$(i),'Facts');

//let c=peek(‘ProductSold’,$(i),'Facts');

let address=peek('City',$(i),'Facts');

GeocodeResponse:

LOAD

status,

//'$(a)' as Pt_FNAME,

//'$(b)' as Pt_LNAME,

//'$(c)' as ProductSold,

'$(address)' as City,

([result/geometry/location/lat]) as latitude,

    ([result/geometry/location/lng]) as longitude

FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=$(address)&sensor=false] (XmlSimple, Table is [GeocodeResponse]);

next i;

Here's what I have come up with in the for loop, but I get a script error. Basically, the logic is: if address is null, try the next i, if it's not null, carry on to the GeocodeResponse.

let noRows = NoOfRows('Facts')-1;

for i=1 to $(noRows)

//     let a=peek('Pt_FNAME',$(i),'Facts');
//       let b=peek('Pt_LNAME',$(i),'Facts');
       //let c=peek(‘ProductSold’,$(i),'Facts');
     let address=peek('City',$(i),'Facts');
     if IsNull ($address)) Then
     Exit FOR
     //also have tried Next i;
     Else 
1 Solution

Accepted Solutions
tamilarasu
Champion
Champion

Hi Tim,

Try this,

Let noRows = NoOfRows('Facts')-1;

for i=1 to $(noRows)

//let a=peek('Pt_FNAME',$(i),'Facts');

//let b=peek('Pt_LNAME',$(i),'Facts');

//let c=peek(‘ProductSold’,$(i),'Facts');

let address=peek('City',$(i),'Facts');

If Not isnull(address) Then

GeocodeResponse:

LOAD

status,

//'$(a)' as Pt_FNAME,

//'$(b)' as Pt_LNAME,

//'$(c)' as ProductSold,

'$(address)' as City,

([result/geometry/location/lat]) as latitude,

    ([result/geometry/location/lng]) as longitude

FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=$(address)&sensor=false] (XmlSimple, Table is [GeocodeResponse]);

ELSE

ENDIF


next i;

View solution in original post

3 Replies
tamilarasu
Champion
Champion

Hi Tim,

Try this,

Let noRows = NoOfRows('Facts')-1;

for i=1 to $(noRows)

//let a=peek('Pt_FNAME',$(i),'Facts');

//let b=peek('Pt_LNAME',$(i),'Facts');

//let c=peek(‘ProductSold’,$(i),'Facts');

let address=peek('City',$(i),'Facts');

If Not isnull(address) Then

GeocodeResponse:

LOAD

status,

//'$(a)' as Pt_FNAME,

//'$(b)' as Pt_LNAME,

//'$(c)' as ProductSold,

'$(address)' as City,

([result/geometry/location/lat]) as latitude,

    ([result/geometry/location/lng]) as longitude

FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=$(address)&sensor=false] (XmlSimple, Table is [GeocodeResponse]);

ELSE

ENDIF


next i;

timmarsh
Contributor III
Contributor III
Author

Winner, winner, chicken dinner. (Except if you're plant powered!)

Thank you so very much Tamil!

And now, onto the troublesome graph plotting!

tamilarasu
Champion
Champion

Ha ha ha. Good luck and have a happy day Tim! .