The gain / loss shown on the M1 Finance platform is the unrealized gain from owning the individual holding or portfolio. An unrealized gain/loss is a profit/loss that exists on paper, resulting from your investments. A gain/loss becomes realized once the position is sold for a profit/loss.
Unrealized Gain/ Loss = Value of Investment - Cost of Investment
Unrealized Gain/Loss % = (Value of Investment - Cost of Investment) / Cost of Investment