For conventional ion traps, the trapping potential is close to independent of the electronic state, providing confinement for ions dependent primarily on their charge-to-mass ratio $Q/m$. In contrast, storing ions within an optical dipole trap results in state-dependent confinement. Here we experimentally study optical dipole potentials for $^{138}mathrm{Ba}^+$ ions stored within two distinctive traps operating at 532 nm and 1064 nm. We prepare the ions in either the $6mathrm{S}_{mathrm{1/2}}$ electronic ground or the $5mathrm{D}_{mathrm{3/2}}$/ $5mathrm{D}_{mathrm{5/2}}$ metastable excited state and probe the relative strength and polarity of the potential. On the one hand, we apply our findings to selectively remove ions from a Coulomb crystal, despite all ions sharing the same $Q/m$. On the other hand, we deterministically purify the trapping volume from parasitic ions in higher-energy orbits, resulting in reliable isolation of Coulomb crystals down to a single ion within a radio-frequency trap.