Validating sum of entries while reaching the last row

Hi,
I have a roster with 6 rows. Each row has a variable val2. I want to check whether the entry in val2 against row6 is equal to row1+row2+ro3+row4+row5

I have written the following code:
(rostert.Where(x=>x.@rowcode>=1 && x.@rowcode<=5).Sum(p=>p.val2)==rostert[6].val2)

But the validation rule is throwing error even before reaching the 6th row. I want this validation row to check the sum only after reaching 6th row
regards
Nilanjana

Rosters are counted starting from 0, so the 1st roster would have index of a 0.
Can you try changing == to !=? and also there is a linq method that allows you to receive index in the Where:

(rostert.Where((index, x) => index < 5).Sum(p=>p.val2) != rostert[5].val2)

thanks a lot. this code is giving compilation error

here is a working condition for you

@rowindex != r1.Count() - 1 && r1.Where((x, index) => index < 5).Sum(p=>p.val2) == r1.Last().val2

replace r1 with your roster name

1 Like