You can do it using LODs
If you have more dimensions than gender in your sheet, add those at the fixed calculation level.
Having said that, attaching package workbook will be better in helping you in future.
Here I have excel data in form of labels(Male/Female), please see below
S.No Gender 1 Male 2 Female 3 Female 4 Male 5 Male 6 Female 7 Male 8 Female 9 Female 10 Male
The mentioned equation should work, didn't it?