Question
A positive charge is distributed uniformly with charge density $\lambda$ along a line of length $L$. Find the electric potential of this charge distribution at point P, a horizontal distance $d$ from the line of charge (taking the potential to be 0 at infinity).
Attempt
I set up the integral as follows $$V = -\int E.dr = -\int_\infty^0 \int_{-d}^{-d-L} \frac{k\lambda}{x^2} dx.dx$$
I have no idea how to evaluate such an integral. My confusion mainly stems from the equality $dx=dx$ implying the infinitesimals are interchangeable hence their corresponding limits are also interchangeable. So which limits to apply first?
Can somebody provide me suggestions (I am aware there are different definitions to $V$ but I would like to use this one. If it's not applicable, please explain)
It's not clear from your question where the point P is supposed to be. I will assume it's on the same line as the charged line segment. But I don't want to limit it to that point: I want to find the electric field anywhere on that line, say at point $x_1$. By symmetry, the electric field will point along the same line. Its magnitude can be calculated as a (single) integral:
$$ E(x_1) = \int_{-L/2}^{L/2} \frac{k\lambda}{(x_1 - x)^2} dx $$
Then to calculate the potential at the point with x-coordinate $d$, you integrate the electric field along the line from $\infty$ to d:
$$ V(d) = - \int_d^{\infty} E(x_1) dx_1 $$
The dot product in the line integral becomes just an ordinary product since the electric field points in the direction of the line (I was not careful about signs, so the sign may be wrong).
But in any case, using different symbols for the different variables of integration should clarify things: first you calculate the electric field at some arbitrary point on the line with coordinate $x_1$, based on the given charge distribution (the first integral - that's just superposition of the electric fields from each tiny little piece of the line charge), then you bring a test charge in from $\infty$ to d, in order to calculate the work done (i.e. the potential - the second integral).