Why did Jesus have to leave for the Holy Spirit to come? John 16:7 Nevertheless I tell you the truth; It is expedient for you that I go away: for if I go not away, the Comforter will not come unto you; but if I depart, I will send him unto you.


Why did Jesus have to go in order for the Holy Spirit to come?
Also does this mean the Holy Spirit was not present before Jesus went away?
Understanding the second part of your question is the key to answering the first part.

Part One: (How the Spirit was with them before and after Jesus "going away")

In John 3:34, it is said of Christ that He had the Spirit of God "without measure". So as He was living on Earth as a perfect sinless man, Jesus had unlimited access to the Holy Spirit, who descended on Him to empower Him for ministry at His baptism. So the Holy Spirit was here, empowering Jesus Christ without measure.

In John 14:16-18, Jesus told the disciples, "you know him, for he dwells with you and shall be in you." So the Spirit of God was with the disciples, but He (the Spirit) was going to be with them and in them in a new way.

Now in the context of John 16:7, Jesus talks about "going away" through the crucifixion (John 16:19-22). But He speaks of the Comforter in ways that also refer to the Spirit's ministry after the ascension (John 16:13). If you think about it, Jesus actually went away from the disciples twice: once for 3 days and nights from death to resurrection, and once at the ascension. There are two "going aways", and there are two events involving the Holy Spirit that are mentioned after each of those "going aways".

First event:

After the crucifixion and resurrection, in the upper room, Jesus breathes on them and says "receive ye the Holy Ghost" (John 20:22). We breathe air in order to live, so this speaks to the aspect of the Spirit's ministry when He regenerates the believer and gives them new life.

Second event:

After the ascension, the disciples waited in Jerusalem to receive power from on high (Acts 1:4-5). This speaks to the Spirit's ministry of empowering believers for service. This is like a mighty rushing wind that can be harnessed to help us do work. Natural air is breathed for life; and as wind, is harnessed for power: so the Spirit gives us life and empowers us for service.

Part 2: Why Jesus had to "go away" in both cases

For Regeneration to occur, the disciples had to have their sins atoned for. This could not occur until after His death and resurrection. So He had to leave them to atone for their sins. Once that was done, He could return and they could "receive the Holy Ghost" when He breathed on them.

For Empowering to occur, it's a little more complicated. The disciples were going to be empowered to help them go and tell others about Jesus. Those people would have to believe their words (John 17:20) to be justified by faith. If Jesus had NOT gone away, it would be simple for everyone to just "go check Him out", see the risen Lord, and prove it. There would be nothing to believe or not believe, there would only be proof that everyone would go check out, so there would be no justification by faith. And there would be no sense empowering the disciples with a measure of faith (Romans 12:3) to do anything because Jesus would be here and would have the Spirit of God without measure. The woman at the well in Samaria ran into something similar (John 4:39-42). At first people believed in Christ because of her words. But then others believed because they went and listened to Him directly, so until His ascension she was out of a job, so to speak.

Part 3: Why Jesus remains away during this Gospel Age

Notice that after the resurrection, Jesus only spends time with those who believed in Him before His death. Had He showed up publicly risen from the dead, there would be proof and no opportunity to believe God's words by faith. (Mankind fell through believing the lies of the Serpent; therefore mankind is justified through believing the words of God). The disciples already believed in Him, so He appeared to them confirming the faith they already had. Now, because He is not on Earth in a bodily form, mankind has the opportunity to respond in faith believing God's words and the freedom to disbelieve if they so choose. 

Also, the church has the opportunity to preach God's words and work together with the Comforter who comes beside us to give us a measure of the Holy Spirit and work together with us to reach the unbeliever. We have a measure of empowering so we have to work together; there are no lone rangers who have it all on their own. When Christ returns to Earth, the time for faith will no longer be here because proof will arrive.

It might be said that Christ "proved it" to Paul and therefore He had no opportunity to believe by faith. But Paul is the one who wrote that we are justified by faith (Romans 5:1) so that perhaps he had the opportunity to reject the vision of Christ He received on the road to Damascus but instead responded by calling Jesus "Lord" (Acts 9:6).

So to sum it up: Jesus had to depart by dying to make regeneration available; and He had to ascend so that empowering for service would be needed to spread God's word. If the risen Christ were here on Earth there would be proof and no opportunity to believe by faith; and there would be no need for empowering to spread God's word because people wouldn't have to hear it and believe, they could just go check it out. Because He left Earth in bodily form, everyone has the opportunity to experience both aspects of the Spirit's ministry in their lives.

And no, the Spirit was present the entire time; but He "came to them" in a different way each time Jesus "departed" from them.

Hope that helps! :)