A new model for numerical analysis of partially coherent x-ray at synchrotron beamlines is presented. The model is based on statistical optics. Four-dimensional coherence function, Mutual Optical Intensity (MOI), is applied to describe the wavefront of the partially coherent light. The propagation of MOI through optical elements in the beamline is deduced with numerical calculation. The coherence of x-ray through beamlines can be acquired. We applied the model to analyze the coherence in the STXM beamline at SSRF, and got the coherence length of the beam at the endstation. To verify the theoretical results, the diffraction experiment of a single slit was performed and the diffraction pattern was simulated to get the coherence length, (31 ± 3.0) µm × (25 ± 2.1) µm (H × V), which had a good agreement with the theoretical results, (30.7 ± 0.6) µm × (31 ± 5.3) µm (H × V). The model is applicable to analyze the coherence in synchrotron beamlines.