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
nirrobi
Helper V
Helper V

Convert txt file according to translation table

Dear PBI community and especially PQ specialists. 

 

I face a situation that I am sure that it's pretty generic but I will try to describe it as I understand it.

 

I have EDI file (txt format) that contains many lines with the same pattern, e.g.

01xxxx1234567y123456789

 

And I need to break it into 3  columns according to dictionary/translation table:

 

From column - column size - column name

1 - 2 - prefix

3 - 11 - container

14 - 10 - BL

 

Attached link to PBIX file with a sample of data, dictionary table and manual query that shows the expected result. 

https://www.dropbox.com/s/mduxyobbrsn42ax/PQ%20parameter%20Table.pbix?dl=0

 

Just to make clear, every line in the EDI file is very long and I have many EDI file I need to translate. 

Every EDI file has different dictionary table. 

 

Any suggestions to automate the process will be much appreciated. 

 

Regards. 

 

Nir

1 ACCEPTED SOLUTION
nirrobi
Helper V
Helper V

I found a solution,

THANK YOU BILL SZYSZ !!

 

The magic is in this line:

Splited = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions(TranslationTable[From Column], false), TranslationTable[Column Name])

 

 

"

You need to create translation table (something like this above) and load it to PQ.
This is code for translation table (Name of this query is TranslationTable

Code:
let    Source = Excel.CurrentWorkbook(){[Name="TranslationTable"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"From Column", Int64.Type}, {"Column Size", Int64.Type}, {"Column Name", type text}}),
    #"Subtracted from Column" = Table.TransformColumns(#"Changed Type", {{"From Column", each _ - 1, type number}})
in
    #"Subtracted from Column"

Then you have to load your txt file to PQ (code below)

Code:
let    Source = Table.FromColumns({Lines.FromBinary(File.Contents("pathToYourTXTFile"), null, null, 1250)}),
    Splited = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions(TranslationTable[From Column], false), TranslationTable[Column Name])
in
    Splited

As you can see, we need only From Column and Column Name columns (Column Size is not necessary)

And voila :-))

"

View solution in original post

3 REPLIES 3
nirrobi
Helper V
Helper V

I found a solution,

THANK YOU BILL SZYSZ !!

 

The magic is in this line:

Splited = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions(TranslationTable[From Column], false), TranslationTable[Column Name])

 

 

"

You need to create translation table (something like this above) and load it to PQ.
This is code for translation table (Name of this query is TranslationTable

Code:
let    Source = Excel.CurrentWorkbook(){[Name="TranslationTable"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"From Column", Int64.Type}, {"Column Size", Int64.Type}, {"Column Name", type text}}),
    #"Subtracted from Column" = Table.TransformColumns(#"Changed Type", {{"From Column", each _ - 1, type number}})
in
    #"Subtracted from Column"

Then you have to load your txt file to PQ (code below)

Code:
let    Source = Table.FromColumns({Lines.FromBinary(File.Contents("pathToYourTXTFile"), null, null, 1250)}),
    Splited = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions(TranslationTable[From Column], false), TranslationTable[Column Name])
in
    Splited

As you can see, we need only From Column and Column Name columns (Column Size is not necessary)

And voila :-))

"

Greg_Deckler
Community Champion
Community Champion

When you say that every file has a different dictionary/translation table, what do you mean exactly? So for some EDI files you would have:

 

1-5 - Prefix

6-19 - Container

20-26 BL

27-30 Something

 

Like that?

 

If that is the case, how many variations of this do you have?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Yes, exactly.
Every edi file come with dictionary table,
I want to have two tables that come from different file , 1-edi, 2-translation
The translation table can have many lines and variations

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