Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
dcasorso
New Member

import text file

I have multiple text files I want to import into tables. They say it is ASCII format, but there are no delimiters. The way it was setup is the first row has a number dashes and then a space, the space indicates the number of characters for each column. My issue is I cannot figure out how to repeat this import without counting the columns each time and entering it in as a delimiter, for example - Csv.Document(File.Contents("C:\Users\Dean\Downloads\SPUD0507.txt"),null,{0, 20, 53, 63, 70, 100, 108, 132, 145, 151, 180, 194},null,1252).

 

Is there someone out there that has completed a task similar to this and is willing to show me how to do it? There is an example of the data

 

Capture.PNG

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@dcasorso

 


@dcasorso wrote:

I have multiple text files I want to import into tables. They say it is ASCII format, but there are no delimiters. The way it was setup is the first row has a number dashes and then a space, the space indicates the number of characters for each column. My issue is I cannot figure out how to repeat this import without counting the columns each time and entering it in as a delimiter, for example - Csv.Document(File.Contents("C:\Users\Dean\Downloads\SPUD0507.txt"),null,{0, 20, 53, 63, 70, 100, 108, 132, 145, 151, 180, 194},null,1252).

 

Is there someone out there that has completed a task similar to this and is willing to show me how to do it? There is an example of the data

 


I do think you should enter the {0, 20, 53, 63, 70, 100, 108, 132, 145, 151, 180, 194} to make things not complicated. However you don't have to count the columns. What you need is a good text editor, such as NotePad++. You'd get the position numbers when putting the input cursor before a space.
Capture.PNG


ImkeF
Super User
Super User

I'd try the following:

 

Select the first record (Source{0}) and add a column: Text.PositionOf([Column1], " ", Occurrence.All)

 

This should return a list with all positions of blanks. Fill in this stepname as a variable into the Csv.Document call (instead of the list with the hardcoded numbers)

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.