Lucky, could you show us some sample data and then the expected output? I'm not sure I understand your question from what you put in the initial post.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills