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
If you save your files into folders that sync to OneDrive for Business or SharePoint, you’ll know the pain that happens if you try to reference a folder based on the path returned by the CELL() function… The SmartFolder 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.
In this article, we’ll explore exactly what this Monkey does, as well as how to use it.
This feature inserts the SmartFolder function into the workbook, allowing you to solve a couple of issues…
The ultimate goal is to provide a list of files in the target folder, with a little future-proofing done in the form of forcing all file extensions to lower case. (This ensures that filtering for an .xlsx file will never miss .XLSX files.) In addition, it also removes the target folder from the Folder name column, making it very easy to see what sub folders (if any) still exist in the list.
On its own these things seem relatively minor, but they are just a convenience for the function’s larger goals…
The real benefit of this function is that it can accept a local drive path to a folder on your system, or the full path to a subfolder on an Office 365 SharePoint site. This makes connecting to a SharePoint folder much easier, as it saves you having to work out the root of the site, connect to it, and then filter the Folder name column to drill down to the files you actually want. The function does all of that for you and can switch easily should your file path “smart switch” from local to SharePoint based on Microsoft’s OneDrive policy implementation. Even better, it does this all without violating the Formula Firewall!
Adding this function to your workbook is very easy.
A new query called fnSmartFolder will be injected directly into your workbook and show up in the Queries & Connections pane, ready for your use.
To invoke the fnSmartFolder function you have multiple different options, depending on your needs. To get started, double click the fnSmartFolder function in the Queries & Connections pane. You will be launched into the Power Query editor, where you will be greeted with full documentation on how to use the function. Feel free to read all of it if you like, or just jump ahead and configure the parameters as outlined below
To list all files in the selected folder and subfolders, all you need to do is scroll down the the Parameters section and:
Upon clicking the Invoke button, you’ll a new query will be created which shows all files in the folder and subfolders.
There are four important things to notice about the output from this function:
When you have hundreds (or thousands) of files in your subfolder hierarchy, the above method can take ages to refresh – even if you are filtering to a specific folder. The reason for this is that Power Query still has to enumerate all files in order to determine if they should be included in your subset or not. WIth a simple switch of the second parameter in this function, we can easily target just the folder, making our refreshes much more efficient.
To list only the files in the targeted folder:
Upon clicking the Invoke button, you’ll a new query will be created which shows the contents of the target folder only:
This result also has some notable components:
To feed this function a dynamic file path, first insert a Parameter Table/Query via the Get Parameter and Query Monkey. Then create a query that passes the file path into the function by using the following steps:
=fnSmartFolder( fnGetParameter("File Path") )
At this point you’ve got the list of all the files from the folder in which you’ve stored the workbook and can filer to subfolders from that location. And the best part? Whether the CELL() function enumerates the local path or SharePoint-hosted path, it will still work!
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