• 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

Merge multiple rows in to one|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Merge multiple rows in to one|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 QueryMerge multiple rows in to one
sp_PrintTopic sp_TopicIcon
Merge multiple rows in to one
Avatar
baxbax
Member
Members

Power Query

Power Pivot
Level 0
Forum Posts: 105
Member Since:
July 11, 2016
sp_UserOfflineSmall Offline
1
October 23, 2019 - 8:24 pm
sp_Permalink sp_Print

Hi,

I have a data extract file which contains some employee contact details. In the file there are multiple rows that relate to the same employee. The number of rows per employee varies. It can be just one or it can be many. The first 4 columns contain the same data for the employee regardless of how many rows there are. The remaining columns have different data on each line.

What I would like to do is combine the rows so that we have just one row per employee. The data for the additional rows would be added as additional columns.

I have added a file that shows the source data format and the required output. This is just example data. In reality there are many more columns in the source data.

Any help greatly appreciated as always.

Regards

Bax

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
October 23, 2019 - 11:06 pm
sp_Permalink sp_Print sp_EditHistory

Hi Bax,

You can Group By the first 4 columns , without aggregation (All Rows)

This will produce a new column with tables. If you look in a table, it will be an extract of the original table with all entries matching the first 4 columns.

In the next step, extract only one column at a time from the tables column, combining the items with any separator you want. I used a line feed below:

let
Source = Excel.CurrentWorkbook(){[Name="Table_Source_Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Mobile", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"applicantid", "First Name", "Surname", "DOB"}, {{"Grouped", each _, type table [applicantid=number, First Name=text, Surname=text, DOB=datetime, email=text, Mobile=anynonnull, Phone=text, Street=text, City=text, PostCode=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Mobile", each Text.Combine( List.RemoveItems(Table.SelectColumns([Grouped],"Mobile")[Mobile],{"NULL"}),"#(lf)")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "email", each Text.Combine( List.RemoveItems(Table.SelectColumns([Grouped],"email"),{"NULL"}),"#(lf)")),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Phone", each Text.Combine( List.RemoveItems(Table.SelectColumns([Grouped],"Phone")[Phone],{"NULL"}),"#(lf)"))
in
#"Added Custom2"

I added 3 columns, you can add the other 3 needed. As you can see, I also removed the entries with "NULL"

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
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.