Not sure why it's not working but this line is wrong
it should be something like is SEL_01 a field or a value? if it's a filed it should be
Also, you're filtering values with an IF statement but also using set analysis. I also don't believe rowno or above will work with the AGGR function.
You should try building a sample application so people here might be able to help you.