So i have just watched this video here: https://www.youtube.com/watch?v=cBbFe9drObk&list=UU3WIohkLkH4GFoMrrWVZZFA
The video displays how the spear is dominant at range and the only way to really counter it with a sword is to get in closer out of reach of the pointy end. That being the case why were soldiers in the medieval period say 1000-1500 given swords if a spear was more effective especially in large groups/formations?
They weren't given swords. Hollywood movie directors like to give their actors swords.
Most mediaeval armies were armed with spears, as were most armies of antiquity. Even after the introduction of gunpowder, many armies, such as the Spanish, continued using formations like the Tercio, made up of combined pike and musket formations.
Swords was a weapon for the elite or for professional soldiers; knights and men-at-arms. Think about it. A sword is difficult to make, and has no purpose apart from battle (at least a spear can be used for hunting). Swords require lots of practice and training, the only people who could become skilled at using them were people with lots of free time (and disposable income). It just wouldn't have been feasible to for armies of the time period you mentioned to "give swords" to everyone, these were armies made up of conscripts who needed to be trained quickly, efficiently, and cheaply (also because they needed to get back to their fields and harvest their crops by October, and were only available for fighting after they had planted their crops in the spring. Very little time was left for training).
And many times, even professional armies were made up mostly of spearmen! For decades in the late middle ages, French military doctrine dictated that victory was impossible unless the core of the army consisted of Swiss Pikemen (a pike is a long spear. Some commenters will also insist that I differentiate between a pike and a halberd).
This makes sense, as battles haven't been series of flashy one-on-one fights as depicted in movies since at least the Bronze Age. They were much closer to masses of people shoving each other. Consequentially, the shoving mass that stayed compact with the longest pointy sticks tended to win.
If you'd like to read more, I'd suggest you check out A History of the Art of War in the Middle Ages, a really cool two-volume book on military history by Sir Charles Oman.
edit:typos
edit 2: A mod and several flared users have pointed out that Oman, from an academic point of view, is not a good reference. Although I believe his book can still be of interest to the layman, for the more academically inclined, I would suggest reading The Lombard League by Gianluca Raccagni (Oxford University Press, 2010), Medieval Warfare by Maurice Keen (Oxford University Press, 1999), and if you can read Italian; I Lombardi Che Fecero L'Impresa by Elena Percivaldi (Ă€ncora, 2009).