Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hola
Estoy buscando un poco de código M con editor de consultas que descomprima y descomprima un archivo zip de un enlace de exportación de URL web
Los datos estarían en forma de archivo CSV una vez exportados y descomprimidos, es un archivo bastante grande (archivo de más de 2,5 millones de filas)
el enlace de URL web que estoy tratando de extraer / descomprimir y descomprimir dentro de PBI es
https://www.doogal.co.uk/files/postcodes.zip
¿Alguien puede ayudar con el código de consulta M que necesitaría para esto?
Muchas gracias
Y
Puede usar cualquiera de los ejemplos (agregué una de mis entradas de blog más antiguas en la parte inferior.
Aquí está su consulta principal
let
Source = Unzip(Web.Contents("https://www.doogal.co.uk/files/postcodes.zip")),
#"Imported CSV" = Csv.Document(Source,[Delimiter=",", Columns=53, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(#"Imported CSV", [PromoteAllScalars=true])
in
#"Promoted Headers"
y aquí está la función Descomprimir (ligeramente modificada):
(ZIPFile as binary) as binary =>
let
//read the entire ZIP file into memory - we'll use it often so this is worth it
Source = Binary.Buffer(ZIPFile),
// get the full size of the ZIP file
Size = Binary.Length(Source),
//Find the start of the central directory at the sixth to last byte
Directory = BinaryFormat.Record([
MiscHeader=BinaryFormat.Binary(Size-6),
Start=BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian)
]) ,
Start = Directory(Source)[Start],
//find the first entry in the directory and get the compressed file size
FirstDirectoryEntry = BinaryFormat.Record([
MiscHeader=BinaryFormat.Binary(Start+20),
FileSize=BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
UnCompressedFileSize=BinaryFormat.Binary(4),
FileNameLen=BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian),
ExtrasLen=BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian)
]) ,
//figure out where the raw data starts
Offset = 30+FirstDirectoryEntry(Source)[FileNameLen]+FirstDirectoryEntry(Source)[ExtrasLen],
Compressed = FirstDirectoryEntry(Source)[FileSize]+1,
//get the raw data of the compressed file
Raw = BinaryFormat.Record([
Header=BinaryFormat.Binary(Offset),
Data=BinaryFormat.Binary(Compressed)
])
// unzip it
in
Binary.Decompress(Raw(Source)[Data], Compression.Deflate)
(1) Trabajar con archivos zip en Power Query - Comunidad de Microsoft Power BI
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |