Has an AFL game ever ended 40-31?
Exactly once. On May 28, 1904, Carlton beat St Kilda 40-31, and no AFL game before or since has ended that way. When it happened it was a scorigami, the first 40-31 in league history.
That makes 40-31 the 3836th most common final score out of 6,607 that have ever occurred in AFL. One point away, 41-31 has happened never and 40-32 has happened 3 times.