HI Qazi,
i know this is an old post, but I am racking my brain on trying to get this to work in InfoPath 2010. I am new to using InfoPath and self-taught - and not a programmer by trade. I can not get the formula: count(preceding-sibling::group2) + 1 to work for me. Can you help me? I can send you the file I am working on.