Skip to main content

Power Query - I : Dynamic Connection To Latest Data in Database

If coding/automation is not about us fooling the machine to get our work done, we haven't yet exploited our powers enough. I, in my daily life, do all sorts of problem-solving involves complex coding, cloud computing, etc. but I get my real kick when I solve the smallest problem like hacking excel, or automation of workflow using power query. Here is my latest gig, I tried to connect to an excel in SharePoint and ensure that every time the database is updated my query picks the latest file. This is the first time I am using power query and it sounds so powerful. So without further delay, let's see what I did:

1. Connect Excel to DataBase: Open an excel file, Select Data from the green ribbon, go to Get Data, select the drop-down on From File, and connect to share point select From SharePoint Folder. 

Fig1: Select DataBase

Once you select the database which is SharePoint in our case, you will get a window like this popping up to connect to it. Put in site url (not the link to file) only connect is to the folder and select OK.

Fig2: Enter URL
2. Find out the file you want to connect:  After clicking OK,  excel connects you to the SharePoint folder and gives you a preview of all the files inside the folder. Since we are aiming to select only one file of our choice we need some modification. 

Fig3: Folder Preview

To access the full list select Transform Data to open the power query editor where you can select the file of your choice. 
Fig4: Power Query Editor
Now, all you need is to take some steps to identify the latest file. 
3. Ensure you have the latest file selected: To get this, pick the Date Modified column, and sort it in Descending column to get the latest file on the top. 
Fig5: Sort the Files
4. Select the first file: So yes, almost there! once your files are sorted, you need to ensure that only the first one is selected - Home -- Keep Rows -- Keep Top Rows -- 1, once you have only one file in your list, now you need to ensure that the name doesn't get hardcoded, so to get this done you need to select the Content column and click on double arrow next to the column name to combine.
Fig6: Combine Latest File
And you are done! Just need to check if the file name is not there in the query.
5. Check the query to confirm the file name is not hardcoded: To look at the query select the relevant table in the file and click Advanced Editor to find out your file name is not there.

Fig7: Query Check
And guess what, you can straight up use this query than performing all these steps. Hope this is helpful Stay tuned!!.

Check out the video here:





Comments

Popular posts from this blog

Data Is the New Oil : From Lenses Of Oil & Gas Industry

Yes, times are difficult but that's what opportunity seekers make the best out of. This pandemic has resulted in a lot of unexpected changes. Most of us don't have a plan anymore because it seems hard to believe when and how our lives would resume. What will the new normal be? Is it ever getting back to the same? Will I ever be able to live my good old life again? How will demand for skills change in near future? What shall we do to maximize the gain from this slow-paced life? With so many questions in their mind, I had an opportunity to talk to a wonderful group of audience in a webinar organized by EAGE RGPIT SC . When I asked them "What is in your mind?"  This was their response. People are worried about their careers. With fancy data lingos, everyone is seeking to learn more about them and trying to prepare for a secured tomorrow. Data science has become more and more popular over the last decade. Being a data scientist is now a software engineer of yesterday. Eve

Shell.AI Residency Program India

This is to call for applications to " AI Residency Program "   recently launched by Shell India. This  a 2-year, full-time, immersive programme, which allows data scientists, AI engineers and computational scientists to gain experience working on a variety of AI projects across all Shell businesses. Recently, Shell India has launched its own, specialized and global programme – bringing digitization – in India to newer heights. Join us, and make history through influencing the future of energy. Along with this, we are also conducting a  hackathon for sustainable and affordable energy  which gives the winners a direct entry to interviews for Shell AI Residency Program.  PS: Jobs will only be offered to people with relevant experience as mentioned in the page while hackathon is open to everyone. Participate and be a part of Journey to a cleaner and more sustainable tomorrow. 

pip install xgboost

I have tried a million ways over years to by-pass all the certs/securities but never had a one right way to do this, xgboost is a very popular ml algorithm but been hard to install. This time finally I made it happen. I downloaded the wheel file directly and installed it to make this happen right. I also have a video for this but this article shows step by step process on how to do it right. Here is how: Open command window from start menu in windows: Fig1: Open Command Window Go to the website to find unofficial binaries 👉 here , find the desired .whl file, in this case, we are looking for xgboost, and download the compatible version with your machine and python: Fig2: The Unofficial Binaries Locate the downloaded file on your machine: Fig3: Locate the Files Install from cmd using pip: Fig4: Install the file  And you are done, you can also follow these steps from my video here: