Yes, intending to do something can be sinful. If you made a firm act of the will, a firm decision, to commit the sinful act, it could be mortal - depending on the gravity of the matter. That being said, it is not the *same *sin, necessarily, as carrying out the actual act. If you had carried out the actual act, in addition to intending to do so, you would have compounded your sin. Is stealing from your brother’s wallet grave matter? That would depend on many factors…how much were you going to steal? How badly would the loss hurt your brother? Killing your neighbour’s dog would almost certainly be grave matter.
Our Lord says in the Gospel that it is “adultery” to even lust after a woman in your heart. Thus, if I lust after the woman next door, and fantasize about sleeping with her, but don’t actually go through with it, I have still committed a sin. It would be another, graver sin to go through with the act - but the intention, the fantasizing is a sin as well.
On the other hand, if the idea simply occurs to you, and you reject it immediately, that is simply a temptation. If you latch onto the idea for a moment, it is probably only a venial sin. If you entertain the idea for a prolonged period, it can become mortal.