• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Organise text file containing records as a list of fields|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Organise text file containing records as a list of fields|Power Query|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryOrganise text file containing recor…
sp_PrintTopic sp_TopicIcon
Organise text file containing records as a list of fields
Avatar
Sjaak Bonenstaak

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
August 5, 2022
sp_UserOfflineSmall Offline
1
April 13, 2023 - 9:35 pm
sp_Permalink sp_Print sp_EditHistory

Hi,

My .txt file is made up of 3 records of 3 journal articles, each with a different title, and a different subset of authors. Each record has a title of the paper, its authors and a journal name. The data organised in the below manner. How would I go about importing this type of file into Power Query, and organise the data into exactly 4 columns: Record Number, Title, Authors and Journal?

Many thanks for your help!

SR - Start of Record
TI - Title01
AU - Author01
AU - Author02
AU - Author03
AU - Author04
JO - Journal01
ER - End of Record
SR - Start of Record
TI - Title02
AU - Author04
AU - Author02
AU - Author03
JO - Journal02
ER - End of Record
SR - Start of Record
TI - Title03
AU - Author01
AU - Author04
JO - Journal01
ER - End of Record

sp_AnswersTopicSeeAnswer See Answer
Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 216
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
2
April 14, 2023 - 2:03 am
sp_Permalink sp_Print

My first thought is to pivot the rows but I'm not sure if I'm totally understanding your current layout. If pivoting the rows doesn't work upload a sample file with a mock-up of what you want the final result to look like and we can help you further. 🙂

Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 490
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
3
April 14, 2023 - 3:15 pm
sp_Permalink sp_Print

Perhaps the attached PQ solution helps you on your way.Screenshot-2023-04-14-at-07.15.17.pngImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage Screenshot-2023-04-14-at-07.15.17.png (14 KB)
sp_AnswersTopicAnswer
Answers Post
Avatar
Sjaak Bonenstaak

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
August 5, 2022
sp_UserOfflineSmall Offline
4
April 15, 2023 - 8:13 pm
sp_Permalink sp_Print

Thanks ever so much, Riny. That's certainly done the trick.

I thought perhaps there was a native Power Query solution dealing with records that are structured in the way of my example. Something along the lines of telling Power Query what the structure of each record is, and PQ then assigning the data according to the user-defined structure. The third step would then be to extract certain fields from each record.

Does that make sense?

Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 490
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
5
April 16, 2023 - 2:28 pm
sp_Permalink sp_Print

Not sure I understand what you mean, but your txt file contains just text. PQ doesn't know these are records and you need to define the logic of it yourself. Thus, the telling part is what you do in the applied steps. Creating a logic that can be repeated over and over again to construct a table with records.

Avatar
Omid Motamedisedeh

New Member
Members
Level 0
Forum Posts: 1
Member Since:
April 26, 2023
sp_UserOfflineSmall Offline
6
April 26, 2023 - 11:00 pm
sp_Permalink sp_Print

Please test the below steps to convert it to the desired record

 

let
Source = Csv.Document(File.Contents("C:\Users
11472235\OneDrive - Queensland University of Technology\Desktop\Author.txt"),null,{0, 3, 5},ExtraValues.Ignore,1252),
Added_Index = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
Indexing = Table.TransformColumns(Added_Index, {"Index", (mn)=> List.Count(List.Select(Table.SelectRows(Added_Index,(ot)=> ot[Index]<mn+1)[Column1],each _="SR "))}),
Grouped_Rows = Table.Group(Indexing, {"Index", "Column1"}, {{"Group", each _[Column3]}}),
Custom1 = Table.TransformColumns(Grouped_Rows,{"Group",each if List.Count(_)=1 then List.First(_) else _}),
#"Grouped Rows" = Table.Group(Custom1, {"Index"}, {{"Grouping", each Table.ToRecords(Table.PromoteHeaders(Table.Transpose(Table.RemoveColumns(_,"Index"))))}}),
#"Expanded Grouping" = Table.ExpandListColumn(#"Grouped Rows", "Grouping"),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Grouping",{"Index"})
in
#"Removed Columns"

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.