# A question about conditional expectation

Let $$X_1,X_2,...,X_n$$ and $$Y$$ be random variables. I know that:

$$\label{aaa}\tag{I} E\left[\sum_{j=1}^n X_j \Bigg | Y \right]=\sum_{j=1}^n E\left[ X_j \Big | Y \right]$$

Now, suppose that $$Y$$ takes values $$1,2, 3,...$$.

How to prove the following? $$E\left[\sum_{j=1}^Y X_j \Bigg | Y \right]=\sum_{j=1}^Y E\left[ X_j \Big | Y \right]$$

Because $$\sum_{j = 1}^Y E[X_j|Y]$$ is $$\sigma(Y)$$-measurable, to show it is the conditional expectation as desired, it is sufficient to show for any $$n \in \{1, 2, \ldots\}$$, it holds that (this is because any $$\sigma(Y)$$-set can be written as the union of sets of the form $$\{Y = n\}$$). \begin{align} \int_{\{Y = n\}}\sum_{j = 1}^Y X_j dP = \int_{\{Y = n\}}\sum_{j = 1}^Y E[X_j|Y]dP. \end{align}
Indeed, \begin{align} LHS &= \int_\Omega \sum_{j = 1}^Y X_j I_{\{Y = n\}}dP = \int_\Omega \sum_{j = 1}^n X_j I_{\{Y = n\}}dP \\ &= \sum_{j = 1}^n\int_{\{Y = n\}}X_jdP \\ &= \sum_{j = 1}^n\int_{\{Y = n\}}E[X_j | Y]dP \\ &= \int_{\{Y = n\}}\sum_{j = 1}^n E[X_j|Y]dP = \int_{\{Y = n\}}\sum_{j = 1}^Y E[X_j|Y]dP = RHS. \end{align}
• Thanks. I only need understand the following $$\sum_{j = 1}^n\int_{\{Y = n\}}X_jdP = \sum_{j = 1}^n\int_{\{Y = n\}}E[X_j | Y]dP$$. Commented Nov 21, 2022 at 5:39