Power Query - Data Cleaning Question

bbalch

Board Regular
Joined
Feb 23, 2015
Messages
61
I'm trying to use Power Query to clean up some data and I've hit a road block. My knowledge in power query is very limited so I'm hoping someone with more experience can help me out.

I've attached a link with screenshots of the data model (original.png) and the desired outcome (desired.png)

I have an "account" column in the data model that includes account numbers / names and splits. Splits are line items broken out of that account, for example the Auto Expense account may have a split for maintenance and another for other. The account numbers are in this format [509050_Auto_Expense] Auto Expense while splits are in this format " Other (00-100 General and Admin)". As seen in original.png

I would like to add a "splits" column that would only pull over the splits from the "account" column and leave it blank if the "accounts" column contains an account number. Then in the "account" column I would like to replace the splits that were moved into the split column with the account number from above. See desired.png as an example.

Original:

Accounts
[509050_Auto Expense] Auto Expense
Other (00-100 General and Admin)

Desired:
Accounts |Splits
[509050_Auto Expense] Auto Expense |
[509050_Auto Expense] Auto Expense | Other (00-100 General and Admin)


https://cmaworld.box.com/s/zbmjey1eqs6k7r8fs2alo548yfp2fmbp

Any suggestions or guidance are greatly appreciated!
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I can't see your sample image, but assuming source is a single column table named Table1 that looks like this:
Code:
[TABLE="width: 245"]
<tbody>[TR]
[TD]Accounts[/TD]
[/TR]
[TR]
[TD][509050_Auto Expense] Auto Expense[/TD]
[/TR]
[TR]
[TD]Other (00-100 General and Admin)[/TD]
[/TR]
[TR]
[TD]Pepsi (Free)[/TD]
[/TR]
[TR]
[TD][509020_Auto Expense] Auto Expense[/TD]
[/TR]
[TR]
[TD][509030_Auto Expense] Auto Expense[/TD]
[/TR]
[TR]
[TD]Pepsi (Free)[/TD]
[/TR]
[TR]
[TD]Pepsi (Lite)[/TD]
[/TR]
[TR]
[TD]Pepsi (Diet)[/TD]
[/TR]
</tbody>[/TABLE]


then this should work
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Replaced Value" = Table.ReplaceValue(Source,"[","[[",Replacer.ReplaceText,{"Accounts"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value", "Accounts", Splitter.SplitTextByEachDelimiter({"["}, QuoteStyle.Csv, false), {"Accounts.1", "Accounts.2"}),
    #"Filled Down" = Table.FillDown(#"Split Column by Delimiter",{"Accounts.2"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Filled Down",{"Accounts.2", "Accounts.1"})
in
    #"Reordered Columns"

It replaces [ with [[ then splits on the first [ then fills down to place the code in blank rows
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top