Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
The first thing we need to know before writing the code is that zip extensions are more complex than gzip. The extension has different compression methods which will make it difficult to read from Power BI. Even though the key will be a Power Query function that I have found many years ago that works for 90% of the cases, I don't think it will always work. It hasn’t fail for me yet.
In order to read a file, we will add a custom function, because Power BI doesn't have a decompress zip function by default. We have to create it.
Let's check my GitHub to get the code.
https://github.com/ibarrau/PowerBi-code/blob/master/PowerQuery/ExtractZIP.pq
Then, inside Power BI Desktop, get data from a blank query to copy the code we have just seen in GitHub in order to create the function.
As you can see, my custom function name will be DecompressZip(). Now that we have the custom function, we need to execute it for a file. We can use the same example of a gzip file with a small difference in the steps, running a function that contains a file as a parameter but without specifying a compression method.
The first step is reading the file. We can get data from a csv and pick up "all files" in the drop-down extension list or modify the code manually from blank query, if you prefer writing it. In any case, it should look like this:
= File.Contents(“C:\Datasets\Energy Data.zip”)
Second Step, add a custom step that will decompress the zip file from the previous step.
= DecompressZip(Origen)
This way, we obtain a similar result like connecting a folder in filesystem. It allows us to explore the content to combine files as one table or to just take one of them.
The next action you choose for Power Query is your own. Now you know how to read a .zip file. I hope it doesn't fail for you and you find it useful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.