A method of examining a sample using a spectroscopic apparatus, such as energy-dispersive X-ray spectroscopy (EDX), comprising the following steps: - Mounting the sample on a sample holder; - Directing a focused input beam of radiation, such as an electron beam or X-ray beam, onto a location on the sample, thereby producing an interaction that causes a flux of stimulated photonic radiation, such as fluorescent X-rays, to emanate from said location; - Examining said flux using a multi-channel photon-counting detector, thus accruing a measured spectrum for said location; - Automatically repeating said directing and examining steps for a series of successive locations on the sample, which method comprises the following steps: - Choosing a beam parameter of the input beam, such as the beam curent or beam spot size, that will influence a magnitude of said flux of stimulated photonic radiation; - For each location within a first set of locations on the sample, accruing a spectrum using a first value of said beam parameter; - For each location within a second set of locations on the sample, accruing a spectrum using a second value of said beam parameter, different from said first value. One application consists in detecting and flagging events during EDX analysis when pile-up is too high and re-acquire EDX data for the locations corresponding to these flagged events.