Forum Discussion
Need to convert a text file to Excel - not the typical comma delineated file
- Jul 21, 2020
IMHO, it's not necessary to change delimiters, in general it's not necessary to make any changes in your text file. For the delimiters you may use split only on left most delimiter, that won't affect the dates.
Variant of layout as TheAntony suggested is in TextTransformTwo query attached.
You can import data from a text file into an existing worksheet.
On the Data tab, in the Get & Transform Data group, click From Text/CSV.
In the Import Data dialog box, locate and double-click the text file that you want to import, and click Import.
In the preview dialog box, you have several options:
Select Load if you want to load the data directly to a new worksheet.
Alternatively, select Load to if you want to load the data to a table, PivotTable/PivotChart, an existing/new Excel worksheet, or simply create a connection. You also have the choice of adding your data to the Data Model.
Select Transform Data if you want to load the data to Power Query, and edit it before bringing it to Excel.
Smith_J Thank you for the input. This is the process I started with - the issue I'm having is understanding how to manipulate the data in power query into multiple columns instead of one column.
Thank you
- SergeiBaklanJul 23, 2020Diamond Contributor
Please ask if any concrete questions while you check the query step by step.
- Maria BakerJul 23, 2020Copper Contributor
SergeiBaklan and @TheAntony - thank you for the assistance on my first request for help. I was able to get the data per Sergei Baklan's instructions & files.
I have another file that needs to be extracted from one column to multiple columns - for my yammer users which I've attached here.
I tried dissecting your files to understand the queries but that was a fail. I would be grateful for your assistance again.
Thank you
- SergeiBaklanJul 24, 2020Diamond Contributor
That's bit another logic of this file. What to do
- since now you have commas within texts, ignore them as default delimiter. That could be done as
= Csv.Document(File.Contents(filePathName),{"Column1"},{0})
which says we split on one Column1 starting from position 0. Other words, no split.
- transforming column we select as names not only field starts by _, but also equal to name
Table.AddColumn(Source, "Names", each if Text.StartsWith([Column1.1],"_") or [Column1.1] = "name" then [Column1.2] else null)
and filter them as other fields as
= Table.SelectRows(#"Filled Down", each not ( Text.StartsWith([Column1.1], "_") or [Column1.1]="name"))
- since field role could be repeated for same person, we created in the middle intermediate table with this field only
group it by names and field (Column1.1), extract list with roles and convert it to text:
after filter field role from main table and append to it above one
- datetime text here is without separation of date and time in the text. Thus we remove comma on the end and insert T between date and time
= Table.ReplaceValue(#"Extracted Text Before Delimiter",each [last_date_accessed], each Text.Insert([last_date_accessed],10,"T"),Replacer.ReplaceText,{"last_date_accessed"})
convert now this text on actual datetime.
- if in another file there is no field last_date_accessed (as in initial one) error appears. If so correct on proper field name or remove the step. That could be handled automatically, but better to know all possible datetime field names.
Please check in attached file.