3 KiB
PBI: Switch table from Import to DirectQuery
Situation
Generally, we like to have all queries pointing at the DWH from PBI reports in DirectQuery mode. This is preferable for a number of reasons, which I won’t cover here to keep things brief.
It might happen that sometimes, for some reason, a report ends up being shipped to production with some query to DWH being set in Import mode. Most common one is just not noticing (been there, done that, no worries).
Issue
This used to be a massive hassle because:
- Once the query is created, PBI won’t allow you to change from one mode to the other.
- This means you can only delete the existing query/table and recreate it.
- Doing this means that everything that’s built on top of of this query (measures, visuals, etc) will go to hell and you’ll have to rebuild it manually. On any report that’s not trivial, this is time consuming and extremely error prone. A clear no-no.
Solution
The solution is to do some good old hacking. You can change the query mode by modifying the source files of the PBI report. This is not supported by PBI and is clearly experimental, so be careful and triple-check once you’ve done it to make sure nothing blew up.
Steps to achieve:
- Let’s imagine we are working on report
MySweetReportwhich contains the queryMyAwfulQuery. The query is currently inImportmode and we want so switch it toDirectQuery. - You are either working on a git branch already. If not, definitely create one.
- Make sure your report is NOT open in PBI Desktop.
- On your branch, make sure to commit or revert all pending changes. Basically, you want to do this from a stable report situation, so you can rollback decently if shit hits the fan.
- Once your git state is blank, look for the report you’re working with in the repo, and open the file
MySweetReport.dataset/model.bim. - This monster JSON has a gazillion things, so let me explain a bit the structure before we pull out our surgery knife:
- The root element contains a key called
tables.tablescontains an array, with one entry for every query you have in your PBI report. Each entry has aname, which should match the name you can see in PBI Desktop. - Each
tableentry will have another key inside calledpartitions, which contains an array. I’ve always found this array to only have one element. I’m not sure under which circumstances it might contain multiple elements. If that’s what you see, I can’t help you, you’re on your own, good luck 🫡. - The only entry within
partitionswill have an entry namedmode. This can either beimportordirectQuery.
- The root element contains a key called
- To switch from
importtodirectQuery... Just replaceimportwithdirectQuery. - Make a commit just with this change so you can easily isolate it in git.
- After this, review the report and triple-check everything is working as expected.
Done!
If you encounter different situations, things don’t work as described here, you find out more hacky tricks around this… Feel free to enrich this page.