[proofplan]
We prove the identity pointwise. First we name the level events $A_j=\{X=a_j\}$ and check that their indicators are well-defined because $X$ is measurable. Then, for an arbitrary $\omega\in\Omega$, the assumption that $a_1,\ldots,a_m$ are exactly the distinct attained values of $X$ gives a unique index $k$ with $X(\omega)=a_k$. At that point all indicator terms vanish except the $k$th one, so the sum equals $a_k=X(\omega)$.
[/proofplan]
custom_env
admin
[step:Define the measurable level events and the candidate sum]
For each $j\in\{1,\ldots,m\}$, define
\begin{align*}
A_j:=\{\omega\in\Omega:X(\omega)=a_j\}=X^{-1}(\{a_j\}).
\end{align*}
Since $\{a_j\}\in\mathcal B(\mathbb R)$ and $X:(\Omega,\mathcal F)\to(\mathbb R,\mathcal B(\mathbb R))$ is measurable, we have $A_j\in\mathcal F$. Hence the indicator map $\mathbb{1}_{A_j}:\Omega\to\{0,1\}$ is well-defined for each $j$.
Define the real-valued function $Y:\Omega\to\mathbb R$ by
\begin{align*}
Y(\omega):=\sum_{j=1}^{m}a_j\mathbb{1}_{A_j}(\omega).
\end{align*}
It remains to prove that $Y(\omega)=X(\omega)$ for every $\omega\in\Omega$.
[/step]
custom_env
admin
[step:Evaluate the sum at an arbitrary outcome]Fix $\omega\in\Omega$. Since $a_1,\ldots,a_m$ are exactly the distinct attained values of $X$, there exists an index $k\in\{1,\ldots,m\}$ such that $X(\omega)=a_k$. Since the values $a_1,\ldots,a_m$ are distinct, this index is unique.
For this $k$, we have $\omega\in A_k$, so $\mathbb{1}_{A_k}(\omega)=1$. If $j\ne k$, then $a_j\ne a_k=X(\omega)$, so $\omega\notin A_j$ and $\mathbb{1}_{A_j}(\omega)=0$. Therefore
\begin{align*}
Y(\omega)=\sum_{j=1}^{m}a_j\mathbb{1}_{A_j}(\omega)=a_k=X(\omega).
\end{align*}[/step]
custom_env
admin
[guided]Fix an arbitrary outcome $\omega\in\Omega$. The goal is to compare the value of $X$ and the value of the finite sum at this same outcome.
Because $a_1,\ldots,a_m$ are exactly the distinct values attained by $X$, the number $X(\omega)$ must be one of the listed values. Hence there exists $k\in\{1,\ldots,m\}$ such that
\begin{align*}
X(\omega)=a_k.
\end{align*}
The distinctness assumption is what makes this index unique: if also $X(\omega)=a_\ell$, then $a_k=a_\ell$, and since the listed values are distinct, $\ell=k$.
Now evaluate each indicator at $\omega$. Since $X(\omega)=a_k$, we have $\omega\in A_k$, and therefore
\begin{align*}
\mathbb{1}_{A_k}(\omega)=1.
\end{align*}
For any $j\in\{1,\ldots,m\}$ with $j\ne k$, distinctness gives $a_j\ne a_k$. Since $X(\omega)=a_k$, it follows that $X(\omega)\ne a_j$, so $\omega\notin A_j$. Thus
\begin{align*}
\mathbb{1}_{A_j}(\omega)=0.
\end{align*}
Substituting these indicator values into the finite sum leaves only the $k$th term:
\begin{align*}
Y(\omega)=\sum_{j=1}^{m}a_j\mathbb{1}_{A_j}(\omega)=a_k\cdot 1+\sum_{\substack{1\le j\le m, j\ne k}}a_j\cdot 0=a_k.
\end{align*}
Since $a_k=X(\omega)$, we obtain $Y(\omega)=X(\omega)$.[/guided]
custom_env
admin
[step:Conclude equality of the two functions]
The outcome $\omega\in\Omega$ was arbitrary, and we proved $Y(\omega)=X(\omega)$ for every $\omega\in\Omega$. Therefore the functions $X$ and $Y$ are equal on $\Omega$, namely
\begin{align*}
X=\sum_{j=1}^{m}a_j\mathbb{1}_{A_j}=\sum_{j=1}^{m}a_j\mathbb{1}_{\{X=a_j\}}.
\end{align*}
This is the desired decomposition.
[/step]