Skip to content

Instantly share code, notes, and snippets.

@msdotnetclr
Last active November 14, 2022 17:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msdotnetclr/9477258a703468578445d6f029fa64a3 to your computer and use it in GitHub Desktop.
Save msdotnetclr/9477258a703468578445d6f029fa64a3 to your computer and use it in GitHub Desktop.
Import GZipped CSV file from the web to Power BI
  1. Get Data -> Web, choose "Basic", enter URL. E.g. https://myteststorage.blob.core.windows.net/pmdogy/20180129/csv/shrmyd/shrmyd.csv.gz?st=2018-02-05T08%3A57%3A00Z&se=2018-02-05T16%3A57%3A00Z&sp=r&sv=2017-04-17&sr=b&sig=PbFVzUv%2FBwrOCR0RcuzgVw%2F9nVFFmbo%2BXOJusO1yo9E%3D Power BI Query Editor will display a single icon for the web blob with the source domain name and content size.
  2. Go to View -> Advanced Editor. The script will be like this:
let
    Source = Web.Contents("https://myteststorage.blob.core.windows.net/pmdogy/20180129/csv/shrmyd/shrmyd.csv.gz?st=2018-02-05T08%3A57%3A00Z&se=2018-02-05T16%3A57%3A00Z&sp=r&sv=2017-04-17&sr=b&sig=PbFVzUv%2FBwrOCR0RcuzgVw%2F9nVFFmbo%2BXOJusO1yo9E%3D")
in
    Source
  1. Add GZip decompression:
let
    Source = Web.Contents("https://myteststorage.blob.core.windows.net/pmdogy/20180129/csv/shrmyd/shrmyd.csv.gz?st=2018-02-05T08%3A57%3A00Z&se=2018-02-05T16%3A57%3A00Z&sp=r&sv=2017-04-17&sr=b&sig=PbFVzUv%2FBwrOCR0RcuzgVw%2F9nVFFmbo%2BXOJusO1yo9E%3D"),
    Decompressed = Binary.Decompress(Source, Compression.GZip)
in
    Decompressed
  1. Power BI Query Editor will display a "CSV" icon. Right click the icon and choose "CSV" from the popup menu. Power BI will extract metadata from the CSV data stream and generate columns and change data types of each column to the best it can. The final outcome looks like this:
let
    Source = Web.Contents("https://myteststorage.blob.core.windows.net/pmdogy/20180129/csv/shrmyd/shrmyd.csv.gz?st=2018-02-05T08%3A57%3A00Z&se=2018-02-05T16%3A57%3A00Z&sp=r&sv=2017-04-17&sr=b&sig=PbFVzUv%2FBwrOCR0RcuzgVw%2F9nVFFmbo%2BXOJusO1yo9E%3D"),
    Decompressed = Binary.Decompress(Source, Compression.GZip),
    #"Imported CSV" = Csv.Document(Decompressed,[Delimiter=",", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Changed Type" = Table.TransformColumnTypes(#"Imported CSV",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}})
in
    #"Changed Type"
  1. Now you can add additional transformation as needed.
@gugoan
Copy link

gugoan commented Apr 1, 2021

Fantastic! Help me a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment