cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
efilipe
Helper IV
Helper IV

Obtener la primera línea del archivo y los valores posicionados

Hola chicos, necesito ayuda.

Necesito leer una carpeta que tiene muchos archivos de texto.

De esos archivos, sólo quiero la primera línea e ignorar las otras líneas.

Entonces necesito obtener unos 20 campos, que son posicional, como:

columna 1 a 3 - ID de cliente

columna 4 a 10 - nombre del cliente

columna 11 tp 17 - estado del cliente

¿Es posible?

¡Gracias!

2 REPLIES 2
Icey
Community Support
Community Support

Hola @efilipe ,

¿Qué te parece esto?

first.gif

O bien, puede hacer referencia a este post para obtener algo como a continuación y luego transponer su tabla.

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"

Saludos

Icey

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

efilipe
Helper IV
Helper IV

Acabo de darme cuenta de que puedo dividir el texto después de importarlo. Así que el problema es conseguir sólo ethe primera línea de cada archivo de texto.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors