Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I'd like to replace in my script some nested previous used to find the last value for a field (in this case, the supply source) in a table that have values similar to:
Tab:
Load *,
If(len(trim(Source2))= 0 or Source2='NULL' or Source2='-', Null(), Source2 ) as Source
INLINE [Trip Stop Type Source2 Pickup Delivered
a1 1 1 a 20 -
a1 2 2 - - 11
a1 3 2 - - 6
a1 4 2 - - 2
a1 5 3 b 18 -
a1 6 2 - - 16
a1 7 4 - - 3
](delimiter is ' ');
This would be a tipical trip, in which there are 4 types of Stops: 1 for initial product pickup, 2 for delivery to customers, 3 for others product pickup (e.g. in a provider) and 4 for product returned to plant.
I need to identify the source for each stop (that would be the previous source untill the truck stop in a provider, changing the source, type 3) and I solve this situation by using nested "previous" function as follow. Could you help me to simplify this scrip? (maybe with peek function or using other one).
My initial solution was:
RESIDENT Tab;
DROP TABLE Tab;
You can try this solution
Tab:
Load *,
If(len(trim(Source2))= 0 or Source2='NULL' or Source2='-', Null(), Source2 ) as Source
INLINE [Trip Stop Type Source2 Pickup Delivered
a1 1 1 a 20 -
a1 2 2 - - 11
a1 3 2 - - 6
a1 4 2 - - 2
a1 5 3 b 18 -
a1 6 2 - - 16
a1 7 4 - - 3
](delimiter is ' ');
Tab2:
load distinct
TripStop,
if(len(trim(Source))=0, peek(Source), Source) as Source;
load distinct
Trip&Stop as TripStop,
Source
Resident Tab;
You can try this solution
Tab:
Load *,
If(len(trim(Source2))= 0 or Source2='NULL' or Source2='-', Null(), Source2 ) as Source
INLINE [Trip Stop Type Source2 Pickup Delivered
a1 1 1 a 20 -
a1 2 2 - - 11
a1 3 2 - - 6
a1 4 2 - - 2
a1 5 3 b 18 -
a1 6 2 - - 16
a1 7 4 - - 3
](delimiter is ' ');
Tab2:
load distinct
TripStop,
if(len(trim(Source))=0, peek(Source), Source) as Source;
load distinct
Trip&Stop as TripStop,
Source
Resident Tab;
Thanks for your support.
I have learned that I could use the "Load" function more than one time when I'm loading data from a resident table 🙂
Thanks a lot!