TL;DR: $$x=2t+\dfrac{\mathrm{e}^{-40t}}{20}$$ solve for t.
I have a function for velocity relative to time:
$$v(t)=\dfrac{gm\left(1-\mathrm{e}^{-\frac{kt}{m}}\right)}{k}$$ g,m and k are all constants
And need to define velocity in terms of distance from the body's initial position (x), so I made the following steps:
v(t)= dx/dt
dx = v(t)dt
x = F(t)
and arrived at:
$$x=\dfrac{gm\mathrm{e}^{-\frac{kt}{m}}\left(\left(kt-m\right)\mathrm{e}^\frac{kt}{m}+m\right)}{k^2}$$
now I want to solve for t in terms x and substitute t(x) into v(t) to get v(x), but have no clue how to do so.
Please ask any questions if I was unclear/help with my conundrum.
Assuming that your equation is correct, to simplify notations, let $\frac{k t}m=T$ and $\alpha=\frac{g m^2}{k^2}$ the expression. This would give $$x=\alpha \left(T+e^{-T}-1\right)\implies T+e^{-T}=\frac x \alpha+1$$ So, now the usual manipulations for Lambert function to get $$T=\left(\frac{x}{\alpha }+1\right)+W\left(-e^{-\left(\frac{x}{\alpha }+1\right)}\right)$$ Beck to the initial variables, this should give $$t=\frac{k }{g m}x+\frac{m}{k}+\frac{m }{k}W\left(-e^{-\left(\frac{k^2 }{g m^2}x+1\right)}\right)$$
Take care that $W(z)$ is real only if $z \geq -\frac 1e$. So, for $$x=2t+\dfrac{\mathrm{e}^{-40t}}{20}\implies t=\frac{x}{2}+\frac{1}{40} W\left(-e^{-20 x}\right)$$ the real solution will exist for $x \geq \frac 1 {50}$.