Active Member
April 29, 2022
Hi Mynda
I try to get data from more than one file in a folder.
Quelle = Folder.Files("..\002.350_2030456_d1"),
#"1" = Table.AddColumn(Quelle, "ExcelDateiinhalt", each Excel.Workbook([Content])),
#"2" = Table.ExpandTableColumn(#"1", "ExcelDateiinhalt", {"Data"}, {"ExcelDateiinhalt.Data"}),
#"3" = Table.AddColumn(#"2", "Header", each Table.PromoteHeaders([ExcelDateiinhalt.Data])),
#"4" = Table.ExpandTableColumn(#"3", "Header", {"partnb", "id"}, {"Header.partnb", "Header.id"}),
The Problem is with the ExpandTableColumn and the Header.id because I can't define it as txpe text (because it is a Serial No).
PowerQuery set type any automaticaly and 2030456.001 --> 2030456.0009999999 or 2030456.010 --> 2030456.01
How can I set the type text before the table expand?
Ciao René
Active Member
April 29, 2022
Thanks for you replay. I'm not sure if I understand you correctly, because I think there is no 'Sample Query'.
That's my current code:
let
Quelle = Folder.Files("Z:\data\002.350_2030456_d1"),
#"Hinzugefügte benutzerdefinierte Spalte" = Table.AddColumn(Quelle, "ExcelDateiinhalt", each Excel.Workbook([Content])),
#"Erweiterte ExcelDateiinhalt" = Table.ExpandTableColumn(#"Hinzugefügte benutzerdefinierte Spalte", "ExcelDateiinhalt", {"Data"}, {"ExcelDateiinhalt.Data"}),
#"Hinzugefügte benutzerdefinierte Spalte1" = Table.AddColumn(#"Erweiterte ExcelDateiinhalt", "Header", each Table.PromoteHeaders([ExcelDateiinhalt.Data])),
#"Erweiterte Header" = Table.ExpandTableColumn(#"Hinzugefügte benutzerdefinierte Spalte1", "Header", {"partnb", "id", "actual", "nominal", "deviation"}, {"Header.partnb", "Header.id", "Header.actual", "Header.nominal", "Header.deviation"}),
#"Gefilterte Zeilen" = Table.SelectRows(#"Erweiterte Header", each ([Header.partnb] <> null)),
#"Entfernte Spalten" = Table.RemoveColumns(#"Gefilterte Zeilen",{"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path", "ExcelDateiinhalt.Data"})
in
#"Entfernte Spalten"
Attached you will find 2 source files.
Moderators
January 31, 2022
You haven't really connected to files in a folder in the way it is meant to be. When you connect to a folder you should at some point expand the "binary" column. A number of helper queries will be generated automatically. One of them is the Sample Query where you do all the major transformations before you load all the files from the connected folder.
The concept is explained in the link below.
https://www.myonlinetraininghu.....m-a-folder
Then I noticed that the "partnb" columns in the source files actually contain the values that are extracted by PQ when you change the type to Text. Not sure where your source files come from or how they are created. Perhaps you can make sure that "partnb" is created as a text with three digits after the "."
Played around with your files a bit and came up with a few steps you could apply in case you can not change the format in the source files.
These are as follows (in English):
It rounds the part number to three digits, then changes the type to text and pads an extra zero ("0") in case there are only two digits in the part number after the point.
Perhaps you can get it to work on your end.
Trusted Members
Moderators
November 1, 2018
Active Member
April 29, 2022
Thanks so much for al your information and ideas.
Now, I understand again the way to use 'double down arrow on the Content column'. It generates this 'Sample Query' and other things. But it doesn't work for me when I change the data type there.
I use another solution for the same result with much less things. Only little code! Please have a look on it again (002.305.zip)
The only problem is with the Table.ExpandTableColumn where I can't set the data type!!!
I think your workaround with round and pad could work. Thanks for this workaround.
1 Guest(s)