• 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

Merging and transposing text values|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Merging and transposing text values|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 QueryMerging and transposing text values
sp_PrintTopic sp_TopicIcon
Merging and transposing text values
Avatar
Prorok Rak

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
October 21, 2018
sp_UserOfflineSmall Offline
1
October 21, 2018 - 8:30 pm
sp_Permalink sp_Print sp_EditHistory

Just few days ago I have discovered that great tool for working with data sources in Excel called Excel Power Query.

I am struggling now how to achieve what I need. Hopefully the picture will be clear enough as for what I have and what I need.

Table.PNGImage Enlarger

I believe it should be possible to achieve this using List.Accumulate function (this page was very helpful: http://radacad.com/list-accumu.....n-power-bi - see the subheading "Accumulate as Concatenate") and then transposing the resulting values by the pivot table function - transpose columns.

Still, I was unable to achieve the needed result because some of the indexes are not unique (highlighted with yellow). I got error on these lines. It worked fine for those lines where the Indexes Merged 2 was unique.

Am I correct in my assumption? Or is there any other way to achieve what I need? I got stucked on this and cannot move on without some hint. Frown

Any help would be greatly appreciated.

sp_PlupAttachments Attachments
  • sp_PlupImage Table.PNG (155 KB)
sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4438
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
October 22, 2018 - 2:01 pm
sp_Permalink sp_Print

Hi Prorok,

Try adding an Index Column to your table (Add Column > Index Column) before your List.Accumulate step. This should fix the error that occurs because you have duplicates.

If that doesn't work please provide your Excel file including your query.

Mynda

Avatar
Prorok Rak

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
October 21, 2018
sp_UserOfflineSmall Offline
3
October 23, 2018 - 2:05 am
sp_Permalink sp_Print

Hi, thank you.

I think it really is the way to go. However, in the meantime I have forgotten how to use the Accumulate function properly. I know that when I tampered with my table I was able almost to get what I needed. Now I cannot remember how I managed to do that. Embarassed

If you could help me with this, I have attached the example file with data and query.

Sheet 1 is just a reminder what I want to achieve.

Sheet 2 contains the data used in the query.

Sheet 3 is the place where the result of query is saved.

Thanks a lot for your help in advance.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
October 23, 2018 - 2:07 pm
sp_Permalink sp_Print

Hi Prorok,

You can do everything via user interface functions.

I would go for Grouping, List.Combine, then Pivot the Index 4 column, last 4 steps are the ones I added to your query (file also attached):

let
Zdroj = Excel.CurrentWorkbook(){[Name="Tabuľka1_2"]}[Content],
#"Zmenený typ" = Table.TransformColumnTypes(Zdroj,{{"Index 1", Int64.Type}, {"Index 2", Int64.Type}, {"Index 3", Int64.Type}, {"Index 4", Int64.Type}, {"Index 5", Int64.Type}, {"TextToMerge", type text}}),
#"Pridaný index" = Table.AddIndexColumn(#"Zmenený typ", "Index Added", 1, 1),
#"Stĺpce so zmeneným poradím" = Table.ReorderColumns(#"Pridaný index",{"Index 1", "Index 2", "Index 3", "Index 4", "Index 5", "Index Added", "TextToMerge"}),
#"Pridané vlastné" = Table.AddColumn(#"Stĺpce so zmeneným poradím", "Indexes Merged 1", each Number.ToText([Index 1])&"."&Number.ToText([Index 2])&"."&Number.ToText([Index 3])),
#"Pridané vlastné3" = Table.AddColumn(#"Pridané vlastné", "Indexes Merged 2", each Number.ToText([Index 1])&"."&Number.ToText([Index 2])&"."&Number.ToText([Index 3])&"-"&Number.ToText([Index 4])),
#"Pridané vlastné1" = Table.AddColumn(#"Pridané vlastné3", "Indexes Merged 3", each Number.ToText([Index 1])&"."&Number.ToText([Index 2])&"."&Number.ToText([Index 3])&"-"&Number.ToText([Index 4])&"."&Number.ToText([Index Added])),
#"Stĺpce so zmeneným poradím1" = Table.ReorderColumns(#"Pridané vlastné1",{"Index 1", "Index 2", "Index 3", "Index 4", "Index 5", "Index Added", "Indexes Merged 1", "Indexes Merged 2", "Indexes Merged 3", "TextToMerge"}),
#"Zoradené riadky" = Table.Sort(#"Stĺpce so zmeneným poradím1",{{"Index 1", Order.Ascending}, {"Index 2", Order.Ascending}, {"Index 3", Order.Ascending}, {"Index 4", Order.Ascending}, {"Index Added", Order.Ascending}}),
#"Pridané vlastné2" = Table.AddColumn(#"Zoradené riadky", "MergedText", each List.Accumulate([TextToMerge],"",(state,current)=>state&current)),
#"Grouped Rows" = Table.Group(#"Pridané vlastné2", {"Index 1", "Index 2", "Index 3", "Index 4"}, {{"Aggregate", each _, type table}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Merge", each Text.Combine([Aggregate][TextToMerge],",")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Aggregate"}),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"Index 4", type text}}, "en-AU"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"Index 4", type text}}, "en-AU")[#"Index 4"]), "Index 4", "Merge")
in
#"Pivoted Column"

sp_AnswersTopicAnswer
Answers Post
Avatar
Prorok Rak

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
October 21, 2018
sp_UserOfflineSmall Offline
5
October 24, 2018 - 5:57 am
sp_Permalink sp_Print

Great! That worked perfectly! And it seems to be even easier solution than what I previously had in mind.

Thank you a lot for your help!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Andy Kirby, Laxmi Praveen
Guest(s) 10
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:
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Marko Meglic
Forum Stats:
Groups: 3
Forums: 24
Topics: 6201
Posts: 27185

 

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