SCD2 Monkey
Coming Soon! Sorry, but this article isn’t quite ready yet. We promise that we’re working on it! In the mean time – until we get
You’ve built an amazing query to connect to a file and clean it up, only to find that when you share the solution the path to the file changes. In simple cases it is just a local file path that changes – and the worst cases it switches between a local file path and SharePoint (or vice versa.) Regardless, it involves editing the query and sometimes rebuilding it from scratch.
The SmartFile function provides the answer to that problem, as you can pass it either a local path on your hard drive or the web path and it will “smart switch” to use the correct Power Query connector to read from the local or SharePoint folder. This function is intended for use in combination with a dynamic filepath setup, as provided by our Parameter Table & Function monkey.
This feature inserts the SmartFile function into the workbook, allowing you to solve a couple of issues…
The ultimate goal is to provide a robust connector that can connect you to a file which is smart enough to determine and deal with changes between local and web hosted files, allowing you to focus on the data cleanup.
In the case of Excel workbooks and Access databases, this connector will also provide an empty blank table in the case the file is not found, which may help prevent breakage in downstream steps of your query.
Adding this function to your workbook is very easy.
A new query called fnSmartFile will be injected directly into your workbook and show up in the Queries & Connections pane, ready for your use.
Before invoking the fnSmartFile query, we recommend that you add a Parameter Table and the fnGetParameter function to your workbook. This will allow you to create dynamic file paths with ease, and allow you to take advantage of the power that the fnSmartFile function has to offer.
If you don’t already have a Parameter Function and Table in your workbook, you can create them quickly via the following steps:
Changes made:
=fnGetParameter( "" )
At this point, you are looking at the table that represents all of the values you can import from the Excel file. From here you could:
And you can do all of this with the assurance that – so long as your data file stays in the same location relative to your solution – that you will be able to refresh it in future.
At this point, you have two options:
In our experience, Power Query does a beautiful job when just double-clicking the file. It will the interpret the data specific to the file using its built-in logic.
We are now ready to release your solution.
When working as consultants, we generally zip up all files in the folder, sent it to our client and ask them to extract them all. When working inside the corporate network it may just be someone accessing the file from a shared drive. In either case, this solution will just work.
The only caveat is when someone stores the solution in a SharePoint sync folder, as Office replaces local file paths with the SharePoint URL, which requires a different connector. And that is the major point of this function. Here’s what to expect when the file path switches from a local to a SharePoint URL:
Coming Soon! Sorry, but this article isn’t quite ready yet. We promise that we’re working on it! In the mean time – until we get
Coming Soon! Sorry, but this article isn’t quite ready yet. We promise that we’re working on it! In the mean time – until we get
Article Overview Many modelers like to store their measures on a single “Measures” table in the data model. If you’re one of them, you may
Coming Soon! Sorry, but this article isn’t quite ready yet. We promise that we’re working on it! In the mean time – until we get
Article Overview One of our favourite tricks is to create a “From Folder” solution which avoids hard-coding a file path, instead pulling it dynamically via