----solved----
Just to let you all know, i have finally solved this issue myself.
I have basically designed a LUT with some of the more fixed data in it as follows:
group,stage,value
grp1, stage1, x1
grp1, stage2, x2
grp1, stage3, x3
grp1, stage4, x4
grp1, stage5, x5
grp2, stage1, x2
grp2...