Variance of random variable $\sum_{k=1}^N X_k$ when $(X_k)$ is independent from $N$ Let $(X_k)$ be an i.i.d. sequence with common distribution $p$ and $N$ is a poisson distribution of parameter $\lambda$ 
Let $Z = \sum_{k=1}^N X_k$. I'm trying to compute the variance of this random variable.
For that we need to compute $E(Z^2) - E(Z)^2 = \sum_{k=0}^\infty e^{-\lambda} \frac{\lambda^m}{m!}E((X_1 + \cdots + X_m)^2)  - E(X_1)h$.
I don't know how to compute the first sum.
Any help will be appreciated 
 A: The sum $$Z = \sum_{k=1}^N X_k$$ is a sum of a random number $N$ of random variables $X_1, \ldots, X_N$.  Thus, we can talk about the conditional random variable $$Z \mid N = \sum_{k=1}^N X_k$$ as being the sum of a known number of random variables, even though notationally, $Z$ and $Z \mid N$ look the same.
Well, what are the expectation and variance of $Z \mid N$?  That is to say, if we regard $N$ as known and fixed, what are the expectation and variance of the sum given $N$?  The expectation is simple enough:  by linearity of expectation, $$\operatorname{E}[Z \mid N] = \sum_{k=1}^N \operatorname{E}[X_k] = N \operatorname{E}[X_k].$$  We can do this because again, $N$ is not random here, but fixed; thus the conditional expectation of $Z$ given $N$ does not need to consider the randomness of $N$.
Similarly, $$\operatorname{Var}[Z \mid N] = \sum_{k=1}^N \operatorname{Var}[X_k] = N \operatorname{Var}[X_k],$$ but here we did require that the $X_k$s are independent, since unlike expectation, the variance of a sum of random variables will generally involve the covariance of those variables--but if they are independent, then $\operatorname{Cov}[X_i, X_j] = 0$ for $i \ne j$.
So in short, we can write $$\operatorname{E}[Z \mid N] = \mu_X N, \quad \operatorname{Var}[Z \mid N] = \sigma_X^2 N,$$ where $\mu_X$ and $\sigma_X^2$ are the mean and variance of a single observation from the sample.
But what about the unconditional variance?  This requires the law of total variance:  $$\operatorname{Var}[Z] = \operatorname{Var}[\operatorname{E}[Z \mid N]] + \operatorname{E}[\operatorname{Var}[Z \mid N]],$$ where the innermost expectation and variances are taken while regarding $N$ as fixed, and the outermost expectation and variances are taken while regarding $N$ as random.  That is to say, $$\operatorname{Var}[\operatorname{E}[Z \mid N]] = \operatorname{Var}[\mu_X N] = \mu_X^2 \operatorname{Var}[N] = \mu_X^2 \lambda,$$ because $\mu_X$ is a scalar constant (parameter).  Then since the variance of a Poisson distribution is equal to its parameter $\lambda$, we get the above result.  Similarly, $$\operatorname{E}[\operatorname{Var}[Z \mid N]] = \operatorname{E}[\sigma_X^2 N] = \sigma^2 \operatorname{E}[N] = \sigma^2 \lambda,$$ therefore $$\operatorname{Var}[Z] = \mu_X^2 \lambda + \sigma_X^2 \lambda = (\mu_X^2 + \sigma_X^2) \lambda,$$ which is the desired total or unconditional variance.
