The application of HTS coils for fully HTS machines has become a new research focus. In the stator of an electrical machine, HTS coils are subjected to a combination of an AC applied current and AC external magnetic field. There is a phase shift between the AC current and AC magnetic field. In order to understand and estimate the total AC loss of HTS coils for electrical machines, we designed and performed a calorimetric measurement for a 2G HTS racetrack coil. Our measurement indicates that the total AC loss is greatly influenced by the phase shift between the applied current and the external magnetic field when the magnetic field is perpendicular to the tape surface. When the applied current and the external magnetic field are in phase, the total AC loss is the highest. When there is a 90 degree phase difference, the total AC loss is the lowest. In order to explain this phenomenon, we employ H formulation and finite element method to model the 2G HTS racetrack coil. Our calculation agrees well with experimental measurements. Two parameters are defined to describe the modulation of the total AC loss in terms of phase difference. The calculation further reveals that the influence of phase difference varies with magnetic field direction. The greatest influence of phase difference is in the perpendicular direction. The study provides key information for large-scale 2G HTS applications, e.g. fully HTS machines and superconducting magnetic energy storage, where the total AC loss subjected to both applied currents and external magnetic fields is a critical parameter for the design.