The formula for signal power is the total energy of the signal, divided by the length of the signal:
$$ P = \frac{E}{N},$$
where $E$ is the energy of the signal, and $N$ is the length in samples.
The total power of the signal is given in both of your equations in the summation. The summation adds together the squared values of all the samples. That value is then divided by the total number of samples in the signal, which gives you the power.
In your upper equation, the signal is assumed to span the samples from $-N$ to $N$, which gives you a total number of $2N+1$ samples. Additionally, the upper equation assumes that the signal is of infinite length, and thus, $N$ approaches infinity in the limit.
The second equation assumes that the signal period is of length $N$, and thus the total energy given by the summation is divided by $N$. I am not sure why the summation goes from 0 to $N$ (N+1 samples), instead of 0 to $N-1$ (N samples), but that might just be a small mistake in the equation. Otherwise it is the same as the other equation.
Note that the $N$ for the periodic signal refers to the length of one period, instead of the length of the whole signal. For a periodic signal, dividing the total energy of one period with the length of that period gives you the same result as dividing the total energy of the whole signal with the length of the whole signal.