Forum

ExpandTableColumn w...
 
Notifications
Clear all

ExpandTableColumn with type text

6 Posts
4 Users
0 Reactions
492 Views
(@rena)
Posts: 3
Active Member
Topic starter
 

Hi Mynda

I try to get data from more than one file in a folder.
Quelle = Folder.Files("..02.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

any.jpg

How can I set the type text before the table expand?

Ciao René

 
Posted : 29/04/2022 11:00 am
(@mynda)
Posts: 4762
Member Admin
 

Go to the Sample Query and change the data type there.

Mynda

 
Posted : 02/05/2022 1:58 am
(@rena)
Posts: 3
Active Member
Topic starter
 

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:data02.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.

 
Posted : 03/05/2022 8:00 am
Riny van Eekelen
(@riny)
Posts: 1217
Member Moderator
 

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.myonlinetraininghub.com/power-query-get-files-from-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):

#"Rounded Off" = Table.TransformColumns(#"Previous Step",{{"partnb", each Number.Round(_, 3), type number}}),
#"Changed Type" = Table.TransformColumnTypes(#"Rounded Off",{{"partnb", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.PadEnd ([partnb], 11, "0" ))

 

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.

 
Posted : 03/05/2022 1:15 pm
(@debaser)
Posts: 838
Member Moderator
 

Assuming the format is consistent, you could also use Number.ToText([Header.partnb],"F3")

 
Posted : 04/05/2022 7:00 am
(@rena)
Posts: 3
Active Member
Topic starter
 

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.

 
Posted : 06/05/2022 3:10 pm
Share: