In Sutton and Barto's RL book, in the section for off-policy learning, we would like to find the expected value of the random variable $G_t$, given $S_t = s$ under our target policy: $$\mathbb{E}_{\pi}[G_t|S_t = s]$$
So here, our random variable is $X = G_t$, meaning returns of states in trajectories/episodes.
Since we want to be able to explore, we use a behavior policy $b$, and therefore sample trajectories(episodes) from it. Computing sample averages doesn't work, as it would converge to $$\mathbb{E}_{b}[G_t|S_t = s]$$ and not $$\mathbb{E}_{\pi}[G_t|S_t = s]$$.
Hence, we use Importance sampling, and here is my understanding of how it works:
$$ \mathbb{E}_{\pi}[X] = \sum_{x \in X} x\pi(x) = \sum_{x \in X} x\pi(x) \frac{b(x)}{b(x)} \implies $$
$$=\sum_{x \in X} x\frac{\pi(x)}{b(x)}b(x) = \sum_{x \in X} x\rho(x)b(x) $$
and in this way, if we know $\rho(x)$, we can do this: $$\frac{1}{n}\sum_{i=1}^{n}\rho(x)x_i \approx \mathbb{E}_{\pi}[X], x \sim b$$.
In Sutton & Barto, in order to calculate this $\rho(x)$, the ratio between the probabilities of the occurrence of a specific trajectory is calculated: $$P(A_tS_{t+1}A_{t+1}...S_T|S_t,A_t)$$
and then the ratio is calculated.
How is this the same as $G_t$? if we want to calculate the return of a specific return $G_t$, we could have many trajectories that give the same return, so we would be underestimating the probability of that return if we find the probability of occurrence for a trajectory.
Where is my gap in understanding?