Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Highlighted
rajeshqvd
Contributor

Script creating new field

IDSubidAreaNewPeekRequired Output
1111   
2221   
3331   
3332INDIND/IND
3333PAKPAK/INDPAK/IND
3334 /PAKPAK/IND

Please help on this need to create new field like "Required Output" .

Labels (2)
1 Solution

Accepted Solutions

Re: Script creating new field

Try this

Table:
LOAD *,
	 If(ID = Previous(ID),
	 	If(Len(Trim(Area)) > 0,
	 		If(Len(Trim(Peek('Output'))) > 0,
	 			Peek('Output') & '/' & Area,
	 			Area),
	 		Peek('Output')),
	 	Area) as Output;
LOAD * INLINE [
    ID, Subid, Area
    111, 1,  
    222, 1,  
    333, 1,  
    333, 2, IND
    333, 3, PAK
    333, 4,  
];
9 Replies
hopkinsc
Valued Contributor II

Re: Script creating new field

Hi, can you explain the logic you need please?

rajeshqvd
Contributor

Re: Script creating new field

Thanks for quick rply....First 3 columns are data 5th one is the required output I am getting 4th one.

Re: Script creating new field

Try this

Table:
LOAD *,
	 If(ID = Previous(ID),
	 	If(Len(Trim(Area)) > 0,
	 		If(Len(Trim(Peek('Output'))) > 0,
	 			Peek('Output') & '/' & Area,
	 			Area),
	 		Peek('Output')),
	 	Area) as Output;
LOAD * INLINE [
    ID, Subid, Area
    111, 1,  
    222, 1,  
    333, 1,  
    333, 2, IND
    333, 3, PAK
    333, 4,  
];
rajeshqvd
Contributor

Re: Script creating new field

Wow your the best
rajeshqvd
Contributor

Re: Script creating new field

IDSubidAreaNewPeekRequired Output
1111   
2221 IND IND
3332INDIND/PAK/IND
3333PAKPAK/INDPAK/IND
3334 /PAKPAK/IND

small change need out put like this....... thanks

Re: Script creating new field

What is the Logic here? and can you explain what the output would look if the data was like this

IDSubidAreaNewPeekRequired Output
1111   
2221 IND IND
3332INDIND/PAK/IND
3333PAKPAK/INDPAK/IND
3334 /PAKPAK/IND
3335AUS ?

 

Will it be AUS/PAK/IND or PAK/IND/AUS or PAK/AUS/IND? Again what is the logic behind the output?

rajeshqvd
Contributor

Re: Script creating new field

if it has n number of values need output like n/n/n/n
if it AUS then output AUS/PAK/IND

Re: Script creating new field

Try this

Table:
LOAD *,
	 If(ID = Previous(ID),
	 	If(Len(Trim(Area)) > 0,
	 		If(Len(Trim(Peek('Output'))) > 0,
	 			Area & '/' & Peek('Output'),
	 			Area),
	 		Peek('Output')),
	 	Area) as Output;
LOAD * INLINE [
    ID, Subid, Area
    111, 1,  
    222, 1,  
    333, 1,  
    333, 2, IND
    333, 3, PAK
    333, 4,  
    333, 5, AUS
];
rajeshqvd
Contributor

Re: Script creating new field

sorry for giving trouble need below output
ID Subid Area Output
111 1
222 1
333 1
333 2 IND AUS/PAK/IND
333 3 PAK AUS/PAK/IND
333 4 AUS/PAK/IND
333 5 AUS AUS/PAK/IND
Community Browser