A point force produces a moment with respect to a point equal to the product of the force by the distance. To compute the moment produced by a system of forces, we can compute the moment for each force and sum the individual moments, or we can just sum the forces and multiply them by the average distance, therefore getting the same moment. Finding the average distance is the same as finding the centre of gravity of the system of forces, since the distance to the center of gravity is the same as the average distance to the forces in the system.
If I'm understanding you, in your formula you are using the distance to the most distant point with distributed load, but most of the load is acting at a shorter distance and therefore producing less moment that the value you are accounting for. If we use the distance to the centre of gravity, some loaded points would be closes to reference points (producing less moment) and some will be further (producing more moment) but the global result will be right.
However, beware that the moment you gave in your question is valid for a cantilever beam with uniform load, and that's not what is in your drawing shows. Your drawing shows a simple supported beam, that is, supported at both ends. The maximum moment in a simple supported beam is $M=\frac{W}{L}\times\frac{L^2}{8}$.
And just a last note: beware that the definition of moment I've used is valid when the direction of the force is perpendicular to the distance to the point, as usually happens when computing moments in beams. If they are not perpendicular, definition of moment should be adjusted.