• 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

Unpivoting data to merge rows|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Unpivoting data to merge rows|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 QueryUnpivoting data to merge rows
sp_PrintTopic sp_TopicIcon
Unpivoting data to merge rows
Avatar
Francis Drouillard

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
March 23, 2023
sp_UserOfflineSmall Offline
1
March 23, 2023 - 3:19 pm
sp_Permalink sp_Print

Tens of thousands of rows of data.

Fields are voterID, Date-1, Date-2, Date-3, Date-4 and Date-5

Rows are sorted by voterID. There are between 1 and 5 rows with the same voter ID.

Each row has a value in one date field only. So, a common pattern for a voter that voted in 5 elections is:

voterID    Date-1    Date-2   Date-3   Date-4    Date-5

voter01         null   voter01      null        null         null

voter01   voter01        null       null        null         null

voter01        null         null       null   voter01        null

voter01        null         null       null        null   voter01

How can I merge all rows to?:

voter01   voter01   voter01      null   voter01   voter01

I don't need to keep the first column. I just need to know when voters voted by date.

What is the best way to approach this data shaping? Power Query? Pivot Table? Power Pivot? Impossible?

Thank you for any insights you share.

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
2
March 23, 2023 - 4:01 pm
sp_Permalink sp_Print

Hi Francis,

Perhaps the PQ example in the attached file will help you on your way. It's a straight-forward Unpivot, Sort and Pivot scenario.

Riny

Avatar
Francis Drouillard

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
March 23, 2023
sp_UserOfflineSmall Offline
3
March 25, 2023 - 3:08 am
sp_Permalink sp_Print

Thank you for your reply, it was very helpful. The result is precisely what I need.

I used the steps to Unpivot. (Found online.) Unfortunately, they didn't work for me. I'm using the latest version of Excel from Office 365. Do you mind briefly describing the procedures you used to obtain the second table?

1. Put your data into an Excel Table

To put your data into a table, click any cell in the dataset and go to the "Insert" tab in the top toolbar. Under the "Tables" section, select "Table." A box appears labeled "Create Table." In this box, verify that the cell range is correct and edit as needed. If not already checked, add a check mark to the "My table has headers" box, if you have column headings, and click the "OK" button. This converts any of your tabular data in the range you selected into an Excel table.

2. Get and transform

Once your data is in an Excel table, you can transform the data to unpivot. Start by clicking any data in a cell within a table. Click on the "Data" tab in the top toolbar. Find the "Get & Transform Data" section and select "From Table / Range." A "Create Table" box opens where you can click "OK." This opens a query editor to unpivot your data.

3. Unpivot your data

In the "Query Editor," right-click on the first column and click "Unpivot Other Columns." This unpivots the data in your other columns within your Excel table. Consider changing the names of the new columns to better represent the data, if you prefer.

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
4
March 25, 2023 - 4:57 am
sp_Permalink sp_Print sp_EditHistory

When you look at the query in my file you should be able to follow the steps I took.

Not sure what source exactly you found on-line but I just created the blue table first. Then I connected to it with PQ and then applied three basic steps.
Unpivot other columns, Sort and Pivot. The last step is just to remove the first column. Then Close and Load to a table. So what exactly isn't clear?

Avatar
Francis Drouillard

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
March 23, 2023
sp_UserOfflineSmall Offline
5
March 25, 2023 - 9:55 am
sp_Permalink sp_Print

Sorry, I'm too much of a newbie at this.

I don't know which column to sort and how, and I don't know how to create a Pivot table. I've tried several different combinations to no avail. I even tried the Pivot tables recommended by Excel, but none are what I want. 

I'm just not able to duplicate your final table, though it is exactly what I want.

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1529
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
March 25, 2023 - 10:04 am
sp_Permalink sp_Print

Hi Francis,

I understand this might be difficult as you don't know how to create a pivot table, but there's no substitute for learning.  So I'd recommend you fill the gaps in your knowledge through our courses, otherwise you'll always struggle to do things like this.

Pivot Table Quick Start Course

Power Query Course

You may also find these articles useful

Power Query Unpivot

Power Query Unpivot Scenarios

Excel Tables

Regards

Phil

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