r/excel • u/tirlibibi17 • Nov 11 '18
Discussion Power Query - A step-by-step example of parsing non-tabular data
Background
It all started about two weeks ago with this post: Should I learn VBA or go straight to Power Query BI?.
'twas a fun - and at times a bit heated - discussion and, at one point, /u/pancak3d argued that:
(...) there are report formats that both VBA and PQ cannot handle
(...)
Mainly things that aren't tabular and gave random junk thrown in. Happens often when you're trying to parse a report that clearly wasn't intended for data analysis
And topped it off with this comment that got me salivating:
Maybe I'll post an example and challenge someone to clean it with PowerQuery
He made good on his promise a week ago: Can this data be parsed with PowerQuery.
I posted a solution and /u/sqylogin expressed interest in seeing a screencast of how I'd done it. So here is a step-by-step reenactment of parsing File 1, in all its unedited beauty, complete with typos, going back to fix mistakes, pausing to answer my wife talking to me etc... I hope you like the captions typed live in Word. I'm too much of a miser to dish out 250 € for Camtasia; maybe if they have a 50% off Black Friday sale...
File 2 is simpler to parse and uses many of the same tricks used for File 1, plus this sh*t takes time, so I'm holding off on recording a video for it for now.
The video
The video shows how I loaded and parsed File 1 starting from scratch. It totals about an hour and ten minutes and is split into four parts available here: Part 1 - Part 2 - Part 3 - Part 4
Other files
The resulting file is slightly different from the one I posted originally, so I'm including it so you can follow along. I'm also including the Word file I was typing into. Both are available on Github in this directory.
Final thought
This is not meant to argue that Power Query is better than VBA. I use both, but since Power Query stepped into my life, I've pretty much stopped using VBA to reformat and aggregate data.
View all comments
Show parent comment
1
u/tirlibibi17 Nov 13 '18
Absolutely. Once your query is built, if the source changes, hit refresh, and you're done.
The data may be clean, but that doesn't mean it's in the format you want/need. Case in point: your example :-) So yes, PQ is extremely useful for "normal scenarios" and can make your spreadsheets faster because the result of query is a static table, not a bunch of clunky formulas, and easier to maintain because you can see the transformations step by step. This post is an intermediate to advanced scenario to prove it can be done, but definitely not representative of average uses of PQ.
To give you an example, my latest PQ mini-project for work is super simple. I'm working on a project where we bill by time spent, so I need a record of everyone's activity with a short descriptions. I set up a template with name, date, start & end times, and details, put it on a shared server, and asked the 5 or 6 people I need the info from to create their own copy and fill it in every day. I then have one consolidation file with a query that picks up all the files and concatenates them into a single one. One merge for rates, a pivot for total price. Bam. Took me about an hour from start to finish.