Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
quser0098
Contributor
Contributor

Check each row value between flags and update the Value field

Hi devs, 

Trying to update the Value column with the highest value for the product by looking into the rows between the flag 1 and -1 in the edit script. I managed to get the output in the front end using above and below functions but I would like to do this in the edit script.

Sample data laid out below and the expected result. 

 

rownoProductflagValue Result
110111 4
210114 4
3101-18  
4101110 10
510112 10
610113 10
7101-11  
810119 15
910116 15
10101110 15
11101115 15
Labels (3)
1 Solution

Accepted Solutions
Saravanan_Desingh

With correction.

tab1:
LOAD *, If(Previous(flag)=-1 Or IsNull(Peek(K1)), RangeSum(Peek(K1),1), Peek(K1)) As K1
;
LOAD * INLINE [
    rowno, Product, flag, Value
    1, 101, 1, 1
    2, 101, 1, 4
    3, 101, -1, 8
    4, 101, 1, 10
    5, 101, 1, 2
    6, 101, 1, 3
    7, 101, -1, 1
    8, 101, 1, 9
    9, 101, 1, 6
    10, 101, 1, 10
    11, 101, 1, 15
    12, 101, -1, 9
];

Left Join(tab1)
LOAD K1, Max(Value) As Result
Resident tab1
Where flag<>-1
Group By K1;

commQV41.PNG

View solution in original post

4 Replies
Saravanan_Desingh

The Result 1 is not 8?

quser0098
Contributor
Contributor
Author

Well, it should ignore -1 value but the range to compare should be from the first row until the row where the flag value is -1.

Saravanan_Desingh

Check this.

tab1:
LOAD *, If(Previous(flag)=-1 Or IsNull(Peek(K1)), RangeSum(Peek(K1),1), Peek(K1)) As K1
;
LOAD * INLINE [
    rowno, Product, flag, Value
    1, 101, 1, 1
    2, 101, 1, 4
    3, 101, -1, 8
    4, 101, 1, 10
    5, 101, 1, 2
    6, 101, 1, 3
    7, 101, -1, 1
    8, 101, 1, 9
    9, 101, 1, 6
    10, 101, 1, 10
    11, 101, 1, 15
    12, 101, -1, 9
];

Left Join(tab1)
LOAD K1, Max(Value) As Result
Resident tab1
Group By K1;

commQV41.PNG

Saravanan_Desingh

With correction.

tab1:
LOAD *, If(Previous(flag)=-1 Or IsNull(Peek(K1)), RangeSum(Peek(K1),1), Peek(K1)) As K1
;
LOAD * INLINE [
    rowno, Product, flag, Value
    1, 101, 1, 1
    2, 101, 1, 4
    3, 101, -1, 8
    4, 101, 1, 10
    5, 101, 1, 2
    6, 101, 1, 3
    7, 101, -1, 1
    8, 101, 1, 9
    9, 101, 1, 6
    10, 101, 1, 10
    11, 101, 1, 15
    12, 101, -1, 9
];

Left Join(tab1)
LOAD K1, Max(Value) As Result
Resident tab1
Where flag<>-1
Group By K1;

commQV41.PNG