The August update for Power Query was finally made available on Sept 1, and it has some pretty cool stuff in it. In this week’s segment I thought we’d cover off one of the features that I’m most excited about as an Excel Pro: Merging columns with Power Query.
The old way
It’s been possible to merge two or more columns together in the past, but you had to write a formula to do it. Honestly, it wasn’t a huge deal, but it still took a bit of know-how and work. Assume, for example, we had this:
And our goal is to concatenate the Account and Dept columns together with a hyphen between them. Here’s what you had to do:
- Insert a New Column (the steps for this varied depending on the version of Power Query you are running. Currently it is Add Column –> Add Custom Column)
- When the prompt pops up you had to provide a formula like shown below:
Okay, so not a huge deal. Just =[Column1] & “-“ & [Column2]
But you still had to write it. I’ve lost count of how many people to whom I’ve taught the simple & shortcut for Excel formulas, but it’s enough to say that it’s probably not intuitive.
So it worked, but could it become easier? We now know the answer is Hell Yeah!
The new way
This time we’ll do it differently…
- Select the Account column
- Hold down CTRL (or SHFT) and select the Dept column
- On the Add Column tab, click Merge Columns
- Choose your separator. The default is –None- (meaning it will just mash them together), but other pre-defined options include Comma, Colon, Equals Sign, Semicolon, Space, Tab
- What I want (a minus sign) isn’t there, so I’m going to choose –Custom–
- Now I’ll enter a – (minus) sign and click OK
And that’s it! My output comes together nicely:
Now, to be fair, I still have to rename the column. I do wish this interface had a way to name the column in advance (like exists when you create a custom column.) Hopefully the PQ team will retrofit us with that ability at some point in the future.
In the mean time, we can either right click the column header and rename it there, or we can edit the column directly in the formula bar. Just change the highlighted part shown below:
Like this:
So honestly, it’s not that much more efficient, why do I think this is cool? Well, it’s not that much more efficient with 2 columns. But try 4. Or when you just need to put 4 columns back together with no spaces in between. Then it starts to make life much easier.
The post Merging Columns with Power Query appeared first on The Ken Puls (Excelguru) Blog.