I guess I need to capture previous:
@SumBOM
if not (Inv = PrevInv and Line = PrevLine and BOM = PrevBOM)
then SumBOM = SumBOM + BOMAmt
PrevInv := Inv
PrevLine := Line
PrevBOM := BOM
and
@SumLine
if not (Inv = PrevInv and Line = PrevLine)
then SumLine = LineAmt + SumBOM
PrevInv := Inv
PrevLine := Line
Anything more elegant come to mind?