Double integration over two random variables order

Suppose that $f(x,y) = 1$ with $0 \leq x \leq 1$ and $0 \leq y \leq 1$ for simplicity. You want to find $P(X \geq 3Y)$ where $X$ and $Y$ are some random variable.

I don't understand why changing the order of integrals gives me a different answer (I am likely missing something fundamental). I proceed the way that supposedly is the right answer:

$$\int_{0}^{1} \int_{0}^{x/3} 1\,dydx = \int_{0}^{1} \frac{x}{3} = \frac{x^2}{6} \biggr\rvert_{0}^{1} = \frac{1}{6}$$

Then I try and see what happens if I do it the other way where instead of isolating the value to the right of the inequality, I just go ahead with the integration and solve for $P(X \geq 3Y)$ as follows:

$$\int_{0}^{1} \int_{0}^{3y} 1\, dxdy = \int_{0}^{1} 3y\,dy = \frac{3y^2}{2} \biggr\rvert_{0}^{1} = \frac{3}{2}$$

I suspect I'm doing some invalid order changing and don't understand why. It has been a long time since I've had to do integrals.

The problem is with the limits of integration in the second case. What happend? You integrate $f(x,y)$ for $$0\le y \le 1, \quad \text{and}\quad 0\le x\le 3y$$ But this means that you allow $x$ to grow up to $3$ when $y=1$ which of course is not correct. If $x$ exceeds $1$ then $f$ is zero. The correct limits would be $$0\le y \le \frac13, \quad \text{and}\quad 0\le x\le 3y$$ To see it in more detail, let's start with the limits you have, but be careful at the point where $f$ changes its type \begin{align}\int_{0}^{1}\int_{0}^{3y}f(x,y)dxdy&=\int_{0}^{\frac13}\int_{0}^{3y}f(x,y)dxdy+\int_{\frac13}^{1}\int_{0}^{3y}f(x,y)dxdy\\&=\int_{0}^{\frac13}\int_{0}^{3y}1dxdy+\int_{\frac13}^{1}\int_{0}^{3y}0dxdy=\frac3{18}+0=\frac16\end{align} as in the first case. In the first case you avoided the mistake accidentally.

The first thing to do it so draw a picture. So draw the square on which the joint density function "lives." Draw the line $x=3y$, which may look more familiar as $y=x/3$.

We want the probability that $Y\le X/3$, so we want the probability that the pair $(X,Y)$ lands in the part $K$ of our square that is below (or on) the line $y=x/3$.

Since the joint density function is the constant $1$, the required probability is just the area of $K$. But since you are integrating, and since we want to deal also with non-constant density functions, let us solve the problem by integrating.

We express the double integral $\iint_K (1)\,dx\,dy$ as an iterated integral.

Let us integrate first with respect to $y$. Then (look at the diagram) for any fixed $x$ between $0$ and $1$, the variable $y$ travels from $0$ to $x/3$, and then $x$ travels from $0$ to $1$. We get your first (correct) integral.

Now let us instead integrate first with respect to $x$. For fixed $y$, the region $K$ starts at $y=x/3$, or equivalently at $x=3y$. So $x$ travels from $3y$ to $1$.

After that, $y$ travels from the bottom of triangle $K$ to the top. The top is reached when $y=(1/3)(1)$. So the correct integral is $$\int_{y=0}^{1/3}\left(\int_{x=3y}^1 (1)\,dx\right)\,dy.$$