Identify specific values in a column and repeat for other rows

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,907
Office Version
  1. 365
Platform
  1. Windows
Hi All

I have a column of mixed information. Every now and then the value refers to a cost centre which is identified as beginning with "cc-". The other values could be other master data fields or even transactional values.

I wish to create a new column called "cost centre" which will always reflect the previously found cost centre. The table below shows the desired output.

Excel 2013
AB
1OriginalNew Col Results
2ValuesCost Centre
3cc-100cc-100
4gasdjcc-100
5jbh scc-100
64598cc-100
7cc-101cc-101
8snkhjcc-101
9109cc-101
10bjhgsacc-101
11cc-102cc-102
12kjhndcc-102
13jkhsdcc-102

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet5



So far my attempts have lead me to this, although I seem unable to reference the identified cost centre from the same column, but from the record above. I get an error produced by the Else statement in CC1; "The field 'Cost Centre1' of the record wasn't found.".

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="tblCC"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Label", type any}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    CC1 = Table.AddColumn(#"Added Index", "Cost Centre1", each if Text.Start(Text.From([Label]),3)="cc-" then Text.From([Label]) else #"Added Index"{[Index]-1}[Cost Centre1])
in
    CC1

...where Label is the column of mixed values


Hope this makes sense.

Regards
Jon
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Jon :)
You cannot reference a column within a column you're just creating in Power Query without using a recursive function. But this would be slow so I don't recommend it.
Instead, you can do the following: Add a custom column with your existing check on "cc-". If true return this value and if false return null instead. Then you check that column and fill down values.

Kind regards, Imke
 
Upvote 0

Forum statistics

Threads
1,215,194
Messages
6,123,569
Members
449,108
Latest member
rache47

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