This is the hard part of GAs (well, that and data representation) and really you can only learn by experience.
Stating the obvious, the function has to be something that measures how good the results are. In particular, it has to be smooth across a wide range of data - whatever the data, your fitness function has to show the right way to improve.
So, for example, a fitness function that is zero unless the answer is right is no good, because it doesn't help you get close to the right answer when you are starting.
And a fitness function that increases as things get better, but doesn't identify the very best solution is not so good either, because your population will improve to a certain point and then get stuck.
So you need to sit down, write out some examples of your data, and then think about what kind of function you can use. You want something that gives low values for bad data and high values for good data. And that adjusts nicely between the two.
Try any crazy idea you can think of at first, and then see how you might put that into a nice mathematical form. Just brainstorm and keep trying and iterating... you will probably find that your first choice isn't so good, and once you run the GA you'll be able to look at what is happening in more detail and improve it.