web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

Flat File to CSV

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi everyone, 

 

I am trying to find a way to take a text file I will be picking from from Sharepoint and reformat it with the end result being a CSV table. Unfortunately this text file has no clear delimiters, and the only thing I have to go off of is character positions. A sample of a file is below, any guidance would be appreciated. 

 

 100-0000 ASSETS H DR B 
 101-0000 CASH ACCOUNTS C DR B 
 101-0001 OPERATING BANK ACCOUNT D DR B 101-0000 

 

Start PositionEnd PositionColumnLength
11BLANK1
210GL8
1113BLANK3
1443DESCRIPTION30
4450BLANK7
5151TYPE 11
5259BLANK8
6061TYPE 22
6271BLANK10
7272TYPE 31
7381BLANK9
8289GL 28

 

Thanks

Categories:
  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @Anonymous 

     

    This is possible with substring.  Your positioning for the latter half of the string seems to be 1 out though.  See below.  Type 1 is position 50, but you list 51.

     

    DamoBird365_0-1626687399351.png

     

    This made it a bit more confusing as substring starts from index 0, so i had to subtract 1 from the start position but then spotted Type 1,2,3 and GL were a further 1 char out of position.  Or at least when I copied/pasted from above it was.

     

    Here's the flow:

    DamoBird365_1-1626687608577.png

     

    and here is the output array:

    DamoBird365_2-1626687649451.png

    The compose with a split is the follow expression:

    split(outputs('Compose'),outputs('Compose_With_A_ReturnKey'))

    and the values of the select consist of the following:

    GL substring(item(),1,8)

    Desc trim(substring(item(),12,30)) [note I used trim to remove trailing and ending spaces - you could do this on all if you wanted].

     

    If you copy the code below, you should then be able to create a new flow and paste it into a new step using the myclipboard tab and this will give you an instant Damo, sorry Demo! 😉

     

    {"id":"badc1a27-1b5f-4779-bef2-3621-a153cc88","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"DamoBird365","operationDefinition":{"type":"Scope","actions":{"Compose":{"type":"Compose","inputs":" 100-0000 ASSETS H DR B \n 101-0000 CASH ACCOUNTS C DR B \n 101-0001 OPERATING BANK ACCOUNT D DR B 101-0000 ","runAfter":{}},"Compose_With_A_ReturnKey":{"type":"Compose","inputs":"\n","runAfter":{"Compose":["Succeeded"]}},"Compose_with_a_Split":{"type":"Compose","inputs":"@split(outputs('Compose'), outputs('Compose_With_A_ReturnKey'))","runAfter":{"Compose_With_A_ReturnKey":["Succeeded"]}},"Select":{"type":"Select","inputs":{"from":"@outputs('Compose_with_a_Split')","select":{"GL":"@substring(item(), 1, 8)","Description":"@trim(substring(item(), 12, 30))","Type1":"@substring(item(), 49, 1)","Type2":"@substring(item(), 58, 1)","Type3":"@substring(item(), 70, 1)","GL 2":"@substring(item(), 80, 8)"}},"runAfter":{"Compose_with_a_Split":["Succeeded"]}}},"runAfter":{}}}

     

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


    P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

     

     

     

     

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @Anonymous 

     

    I should have said that you can stick the output of the select into the create csv table and you will get the following result:

     

    DamoBird365_4-1626688617041.png

     

     

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


    P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

  • kevinsa Profile Picture
    29 on at

    @DamoBird365 , your solution was exactly what I was looking for. I have run into this error though, 

     

    The 'start index' for function 'substring' must be equal to or greater than zero and must be less than '0' which is the length of the string.

     

    I think I've been able to narrow it down with a \n being added to the last line in the text file (a blank line) from 'Split with a ReturnKey'. I manually remove the line and all works as expected. I'm just not sure how to trim the end off. 

     

    kevinsa_0-1627242596617.png

     

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @kevinsa 

     

    You could use take() https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#take based on sum(length(array),-1)

     

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


    P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 315 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 267

#3
Henil Profile Picture

Henil 115

Last 30 days Overall leaderboard