Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
rajeshqvd
Creator II
Creator II

Finding Range in Script

Hello, need help on create new field in script below output required where ever data = 'AB' that recognize Cycle1 after that need to increment Cycle'N'(Cycle1,Cycle2,Cycle3)  

IDDataOutput
111aCycle1
111bCycle1
111cCycle1
111dCycle1
111ABCycle1
111jCycle2
111kCycle2
111ABCycle2
111klCycle3
111hgCycle3
111hggCycle3
111ABCycle3
222aCycle1
222cCycle1
222dCycle1
222eCycle1
222ABCycle1
222aaCycle2
222ffCycle2
222ABCycle2
1 Solution

Accepted Solutions
sunny_talwar

Try this

Table:
LOAD RowNo() as RowNum,
	 *,
	 If(ID = Previous(ID), If(Previous(Data) = 'AB', RangeSum(Peek('CycleNum'), 1), Peek('CycleNum')), 1) as CycleNum,
	 'Cycle' & If(ID = Previous(ID), If(Previous(Data) = 'AB', RangeSum(Peek('CycleNum'), 1), Peek('CycleNum')), 1) as Output;
LOAD * INLINE [
    ID, Data
    111, a
    111, b
    111, c
    111, d
    111, AB
    111, j
    111, k
    111, AB
    111, kl
    111, hg
    111, hgg
    111, AB
    222, a
    222, c
    222, d
    222, e
    222, AB
    222, aa
    222, ff
    222, AB
];

View solution in original post

9 Replies
tresesco
MVP
MVP

Try like:

Load *,
	If(Data='AB', 'Cycle'&AutoNumber(Data&RowNo()),Output) as OutputNew
rajeshqvd
Creator II
Creator II
Author

thanks for your response...NO its giving continues increment and that output field is required out put 

tresesco
MVP
MVP

Could you post your input and expected output ?
rajeshqvd
Creator II
Creator II
Author

This is the Data
ID Data
111 a
111 b
111 c
111 d
111 AB
111 j
111 k
111 AB
111 kl
111 hg
111 hgg
111 AB
222 a
222 c
222 d
222 e
222 AB
222 aa
222 ff
222 AB
this is required Output
Output
Cycle1
Cycle1
Cycle1
Cycle1
Cycle1
Cycle2
Cycle2
Cycle2
Cycle3
Cycle3
Cycle3
Cycle3
Cycle1
Cycle1
Cycle1
Cycle1
Cycle1
Cycle2
Cycle2
Cycle2
sunny_talwar

Try this

Table:
LOAD RowNo() as RowNum,
	 *,
	 If(ID = Previous(ID), If(Previous(Data) = 'AB', RangeSum(Peek('CycleNum'), 1), Peek('CycleNum')), 1) as CycleNum,
	 'Cycle' & If(ID = Previous(ID), If(Previous(Data) = 'AB', RangeSum(Peek('CycleNum'), 1), Peek('CycleNum')), 1) as Output;
LOAD * INLINE [
    ID, Data
    111, a
    111, b
    111, c
    111, d
    111, AB
    111, j
    111, k
    111, AB
    111, kl
    111, hg
    111, hgg
    111, AB
    222, a
    222, c
    222, d
    222, e
    222, AB
    222, aa
    222, ff
    222, AB
];
rajeshqvd
Creator II
Creator II
Author

WOW.... Sunny your fast and Best...Thank you for your support
rajeshqvd
Creator II
Creator II
Author

HI Sunny,
I am facing below issue.

ID Data Output Output should be
222 AB Cycle1 Cycle1
222 AB Cycle2 Cycle2
222 AB Cycle3 Cycle3
222 e Cycle4 Cycle3
222 ffg Cycle4 Cycle3
222 aa Cycle4 Cycle3
222 ff Cycle4 Cycle3
222 df Cycle4 Cycle3

but in other scenario it coming correctly
ID Data Output
111 a Cycle1
111 b Cycle1
111 c Cycle1
111 d Cycle1
111 AB Cycle1
111 j Cycle2
111 k Cycle2
111 AB Cycle2
111 kl Cycle3
111 hg Cycle3
111 hgg Cycle3
111 AB Cycle3
sunny_talwar

Please open a new thread to explain what the issue is and we can go from there?