A first-principles approach for calculating ion separation in solution through two-dimensional (2D) membranes is proposed and applied. Ionic energy profiles across the membrane are obtained first, where solvation effects are simulated explicitly with machine-learning molecular dynamics, electrostatic corrections are applied to remove finite-size capacitive effects, and a mean-field treatment of the charging of the electrochemical double layer is used. Entropic contributions are assessed analytically and validated against thermodynamic integration. Ionic separations are then inferred through a microkinetic model of the filtration process, accounting for steady-state charge separation effects across the membrane. The approach is applied to Li+, Na+, K+ sieving through a crown-ether functionalized graphene membrane, with a case study of the mechanisms for a highly selective and efficient extraction of lithium from aqueous solutions.