

February 9, 2022

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.


July 16, 2010

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


October 5, 2010

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


February 9, 2022

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.
Now I will go look at Mynda's solution. Thanks again to both of you for your help!
Cullen


February 9, 2022

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.

1 Guest(s)
