• 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Advice on transforming data|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Advice on transforming data|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
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 QueryAdvice on transforming data
sp_PrintTopic sp_TopicIcon
Advice on transforming data
Avatar
Richard K
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 4, 2020
sp_UserOfflineSmall Offline
1
January 5, 2022 - 10:20 am
sp_Permalink sp_Print sp_EditHistory

I have a program which records and outputs values to a csv file, however the data is difficult to organise so i'm looking for a way of transforming the data into a more typical table format. I was thinking that power query could be the way to do it but not sure how to go about it.

I've attached two file, one is the "PRE" which is how it is output from the program, with data added in pairs per line.

The other is the "FINAL" which is how I would like the data to be arranged.

If anyone has any advice on how I could do it that would be greatly appreciated.

sp_AnswersTopicSeeAnswer See Answer
Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 613
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
January 5, 2022 - 9:44 pm
sp_Permalink sp_Print

Maybe something like this:

 

let
Source = Excel.Workbook(File.Contents("C:\path to your file here\PRE.xlsx"), null, true),
PRE_Sheet = Source{[Item="PRE",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(PRE_Sheet, [PromoteAllScalars=true]),
#"Added Custom" = Table.AddColumn(#"Promoted Headers", "FieldList", each List.Range(Record.ToList(_), 5)),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "signal_back_price", each try List.Range([FieldList], List.PositionOf([FieldList], "signal_back_price"), 2){1} otherwise null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"FieldList"}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Time", "Market", "Automation instance", "Section type:Event/Market/{Selection Name}", "Count of name/value pairs in this Section before next Section column", "signal_back_price"}, "Attribute", "Value"),
#"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Removed Columns1", "Prefix", each if [Value] is text then Text.BeforeDelimiter(Text.From([Value], "en-GB"), "-") else null, type text),
#"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Header", each if [Value] is text then Text.AfterDelimiter(Text.From([Value], "en-GB"), "-") else null, type text),
#"Filled Down" = Table.FillDown(#"Inserted Text After Delimiter",{"Prefix", "Header"}),
#"Added Index" = Table.AddIndexColumn(#"Filled Down", "Index", 0, 1),
#"Added Custom2" = Table.AddColumn(#"Added Index", "Keep", each Number.Mod([Index], 2) = 1),
#"Filtered Rows" = Table.SelectRows(#"Added Custom2", each ([Keep] = true) and ([Prefix] <> "signal_back_price")),
#"Removed Columns2" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Keep"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns2", List.Distinct(#"Removed Columns2"[Header]), "Header", "Value", List.Sum),
#"Removed Columns3" = Table.RemoveColumns(#"Pivoted Column",{"Count of name/value pairs in this Section before next Section column", "Automation instance"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns3",{"Time", "Market", "Section type:Event/Market/{Selection Name}", "Prefix", "signal_back_price", "back_price", "initial_stop_price", "layhigh", "laylow", "target_price", "trigger_high_traded_price", "trigger_low_traded_price", "trigger_no_of_selections", "trigger_sec_untill_start", "trigger_sel_vol", "trigger_sel_vol%"}),
#"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Time", type datetime}, {"Market", type text}, {"Section type:Event/Market/{Selection Name}", type text}, {"Prefix", type text}, {"signal_back_price", type number}, {"back_price", type number}, {"initial_stop_price", type number}, {"layhigh", type number}, {"laylow", type number}, {"target_price", type number}, {"trigger_high_traded_price", type number}, {"trigger_low_traded_price", type number}, {"trigger_no_of_selections", type number}, {"trigger_sec_untill_start", type number}, {"trigger_sel_vol", type number}, {"trigger_sel_vol%", type number}})
in
#"Changed Type"

sp_AnswersTopicAnswer
Answers Post
Avatar
Richard K
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 4, 2020
sp_UserOfflineSmall Offline
3
January 7, 2022 - 9:18 am
sp_Permalink sp_Print

Thank you so much, that works a treat.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Andy Kirby
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
wahab tunde
Cong Le Duc
Faisal Bashir
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Len Matthews
Kristine Arthy
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27210

 

Member Stats:
Guest Posters: 49
Members: 31878
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.