If the basic idea is the same then perhaps you can alter your approach to it and use appropriate grouping and ordering to not then limit by a particular number.
As I understand it the basic jist is what you are saying here:
....'I need to subtract the current value from JUST the previous one, not all the previous ones. So if there's a value for Run#s 3, 4, and 5, 3 will show its own value since there's nothing before it, 4 should be its value minus the value from 3, and 5 should be its value minus the original value from 4, not the formulated value of 4 minus 3. And this is only if they share the same JobCode. That part is all worked out though thanks to Madawc...'
Surely if you are grouping by JobCode and then grouping within that by Run# then you ought be able to perform these calculations without the restriction or formulae for each specific Run #?
Something like:
if {PV_JobWIP.RunNumber} = minimum({PV_JobWIP.JobCode},{PV_JobWIP.RunNumber})
then
sum(minimum({PV_JobWIP.JobCode},{PV_JobWIP.RunNumber}),{PV_JobWIP.MatVarValue})
else
sum({PV_JobWIP.RunNumber},{PV_JobWIP.MatVarValue})-
sum(previous({PV_JobWIP.RunNumber}),{PV_JobWIP.MatVarValue})
I'll sling some test figures together and test the logic later on.
Some sample data may help though. LBass has a point in that the current approach is very unweildy and cubersome when it doesn't need to be.
'J