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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
efilipe
Helper IV
Helper IV

Get first line of the file and positioned values

Hi guys, need help.

 

I need to read a folder that has many text files.

 

From those files, I want only the first line and ignore the other lines.

 

Then I need to get about 20 fields, that are positional, like:

 

column 1 to 3 = client ID

column 4 to 10 = client name

column 11 tp 17 = client state

 

Is that possible?

 

Thanks!

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @efilipe ,

 

How about this?

first.gif

 

Or, you can refer to this post to get something like below and then transpose your table.

test.PNG

tr.PNG

trs.PNG

let
    filesInFolder = Folder.Files("D:\Folder Test\"),
    GetFirstRowOfCsv = (someFile as binary) as list => 
        let
            csv = Csv.Document(someFile, [Delimiter=" ", Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
            promoted = Table.PromoteHeaders(csv, [PromoteAllScalars=true]),
            firstRow = Table.ColumnNames(promoted)
        in firstRow,
    firstRowExtracted = Table.AddColumn(filesInFolder, "firstRowExtracted", each GetFirstRowOfCsv([Content]), type list),
    combined = 
        let
            columns = firstRowExtracted[firstRowExtracted],
            headers = List.Transform(firstRowExtracted[Name], each Text.BeforeDelimiter(_, ".txt")),
            toTable = Table.FromColumns(columns, headers)
        in toTable,
    #"Transposed Table" = Table.Transpose(combined)
in
    #"Transposed Table"

 

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @efilipe ,

 

How about this?

first.gif

 

Or, you can refer to this post to get something like below and then transpose your table.

test.PNG

tr.PNG

trs.PNG

let
    filesInFolder = Folder.Files("D:\Folder Test\"),
    GetFirstRowOfCsv = (someFile as binary) as list => 
        let
            csv = Csv.Document(someFile, [Delimiter=" ", Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
            promoted = Table.PromoteHeaders(csv, [PromoteAllScalars=true]),
            firstRow = Table.ColumnNames(promoted)
        in firstRow,
    firstRowExtracted = Table.AddColumn(filesInFolder, "firstRowExtracted", each GetFirstRowOfCsv([Content]), type list),
    combined = 
        let
            columns = firstRowExtracted[firstRowExtracted],
            headers = List.Transform(firstRowExtracted[Name], each Text.BeforeDelimiter(_, ".txt")),
            toTable = Table.FromColumns(columns, headers)
        in toTable,
    #"Transposed Table" = Table.Transpose(combined)
in
    #"Transposed Table"

 

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

efilipe
Helper IV
Helper IV

I just realized I can split the text after importing. So the problem is getting only ethe first line of each text file.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors