• 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

Power Query to unstack data when it doesn't recur regularly|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Power Query to unstack data when it doesn't recur regularly|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 QueryPower Query to unstack data when it…
sp_PrintTopic sp_TopicIcon
Power Query to unstack data when it doesn't recur regularly
Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
1
February 9, 2022 - 2:27 am
sp_Permalink sp_Print

I am using Excel in Office365 on a PC. I have attached a sample workbook with dummy data that shows the issue I have.

I get my data by copying and pasting it from a system into a worksheet. The data is in ten regular columns named Item, Date, Type, Category, TK (timekeeper name), Rate, Units (hours), Desc, Adj, Amt, and an additional Column1. In addition, sometimes there are full blank rows interspersed within the data (I know how to fix that).

My problem is that the Date column has stacked data I want to unstack. The problem is that the stacked data can vary: although it always has the actual date (on the same row as the Item number) and then rows containing Project, Activity, and Description information, an Item sometimes has another row that starts with Warning (e.g., if a timekeeper has billed more than 12 hours). So, sometimes an Item has four rows under Date and sometimes it has five rows (if an Item has a Warning).

I would like to use Power Query to clean this up: leaving the actual Date by itself in the Date column, moving the Project, Activity, Description and (when it occurs) Warning data from rows under Date into their own columns, all lined up so that for each Item all invoice information is on a single row. 

sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4446
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
February 9, 2022 - 11:48 am
sp_Permalink sp_Print

Hi Cullen,

Welcome to our forum! Obviously this requires a different approach which has quite a few steps, but most importantly, the warnings need to be extracted to their own query, which you then merge back to the original data. I've attached your file with the solution. Hopefully you can follow the 'applied steps' to understand how to approach it.

Hope that helps.

Mynda

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
3
February 9, 2022 - 12:26 pm
sp_Permalink sp_Print

Hi Cullen,

Seems that Mynda and I were both working on this and didn't know the other was doing so!  At least you get 2 different solutions to your problem.

My query involves:

- Adding an Index column

- Splitting the Date column to separate data from its description

- Pivoting that new data column

- Sorting and filling the other columns

- Adding a Custom Column that counts the number of rows for each Item.  5 rows means there's a warning so that warning message goes into the Custom Column otherwise it's null.

- Filtering out rows in the Type column that are null, leaving you with your final data table

regards

Phil

Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
4
February 9, 2022 - 11:51 pm
sp_Permalink sp_Print sp_EditHistory

Hi Phil and Mynda, 

Thank you both very much for the solutions. I have gone through Phil's so far, but it's taking me some time to appreciate what each step does and why (which I think is necessary to really get all the benefit of his explanation and hopefully be able to apply it to other problems I may face in future).

Looks like the key step was "Added Custom3" (this took me a while to figure out since I was looking for a column by that name . . .), which counts the number of times each number appears in Item and either fills in null (if #<5) or the value from the Warning column - if/then/else logic that's perfect for my situation where I either have four or five rows in the original data, never more or less. The only problem with this solution is that there is no data in the Project, Activity, or Description columns, only Warning. missing-data-in-columns.JPGImage Enlarger

Now I will go look at Mynda's solution. Thanks again to both of you for your help!

Cullen

sp_PlupAttachments Attachments
  • sp_PlupImage missing-data-in-columns.JPG (39 KB)
Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
5
February 10, 2022 - 12:13 am
sp_Permalink sp_Print

I have opened Mynda's file, but don't see a solution in it (there is no query) - it looks to be just the original data. Maybe I should look up this idea of extracting rows to their own query and then merging?

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4446
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
6
February 10, 2022 - 7:56 am
sp_Permalink sp_Print

Hi Cullen,

Go to the Data tab > Queries and Connections. In the Queries and Connections pane that opens you'll see two 'connection only' queries. It's the Details query that contains the final result.

Mynda

Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
7
February 10, 2022 - 11:49 pm
sp_Permalink sp_Print

Sorry for not finding that sooner, Mynda - noobie error!

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
8
February 17, 2022 - 3:34 pm
sp_Permalink sp_Print sp_EditHistory

Hi Cullen,

Yes the #"Added Custom3" step does as you describe.

Not sure how the Project, Activity and Description columns ended up blank in my first file.  I've fixed that in this file.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
9
February 26, 2022 - 6:06 am
sp_Permalink sp_Print

Sorry to jump back to this, but I have found an issue with Mynda's solution: although the original data only had Warnings for three of the items (2, 7, & 9), and Mynda's Warnings table only shows 3 rows (consistent with that), the Merged Queries (combining Details and Warning from Mynda's solution) have Warnings appearing in five rows (1, 2, 6, 7, & 9).

I have attached a couple of pictures. Merged-Queries-return-5-items-with-Warnings.JPGImage Enlarger

Original-data-has-only-3-items-with-Warnings.JPGImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage Merged-Queries-return-5-items-with-Warnings.JPG (42 KB)
  • sp_PlupImage Original-data-has-only-3-items-with-Warnings.JPG (142 KB)
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Richard West, Shanna Henseler, Lawrence Smith, Nada Perovic
Guest(s) 12
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:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27236

 

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