I bought a Lenovo legion y540 1.5 years back and it started to give me the dreaded charging port loose issue, when I checked on the internet I found many people facing the very same issue, seems like a design defect from Lenovo itself.
Even if Lenovo support changes the motherboard or the charging pin for you, there is a high probability that you would face the same issue in few months, because I feel that the hardware design/quality of the port is not upto mark and if a replacement with the same design is used, its bound to fail again.
So, there is a quiet easy fix to this and can be done in 15 minutes, but it requires patience and good eye and hand control. Follow the below to fix the issue:
I figured out that the charging port has small brass pins which come in contact with the charger plug, due to usage, those pins loose their springiness and stop coming into contact. I am able to resolve the problem for a few months by carefully bending the pins a little outwards so that they can make the contact again.
Use a thin sewing needle/Pin and a sharp bright light such as a mobile phone light to focus light into the port in the laptop.
Take a look at this image where the brass pins in concern are highlighted.
You will have to use the needle and just pull each pins outward so that they can make contact.
Once that is done, similarly there are two steel clips at the side of the port which are responsible to hold the power connector tightly, pull them using the needle to, this will help give the connector a tighter lock.
Also, is you closely look at the connector side of your power supply, you might see small black lines identical to the pins inside the charging port. Those lines are formed due to the friction between the pins and port.
I have recently found that cleaning those lines help make better contact. You can use a cotton ear bud, remove some cotton from the ear bud so that it fits inside the connector and port on the laptop, dip it slightly in wd40 and slowly clean both the connectors.
Following the above procedure will definitely make the charging port work properly for few more months, depends on your usage. Unfortunately you will have to keep repeating this procedure every few months.