Add a new column in Excel repeating data in a single Cell in a column that also has data that I do not want in the column using Power Query

Willforth

New Member
Joined
Aug 2, 2011
Messages
35
Office Version
  1. 365
Platform
  1. Windows
I apologise for the confused title but I do not know how to succinctly describe my request for help. I thought it best to create a table to show what I mean (see below).

The text in green shows the name I already have in my table and it's location. I want to use Power Query to add a new column (shown in red) and insert the green text in all the rows where there is a day of the week showing in Column A (See yellow text for where I want the copied data inserted).

The next block of data starts with a new name (see second instance of green text) and I want that placed in the next set of rows where there is a day of the week showing in Column A (See yellow text for where I want the copied data inserted). I have around 100 names that need to be inserted in this manner so it is a long list.

I have tried Inserting a column using a conditional statement but frankly, all I am getting is frustration.

Please can you help a Newbie?

Name 1
DayDateSomethingSomething elseSomething moreStaff Name
MonName 1
TueName 1
SunName 1
Name 2
Day
MonName 2
ThuName 2
 
StaffDateStartFinishBreakClientTimesheetCommentPay-HrPay-NamePay-CodeSales-HrSales-NameSales-CodeMultiplierHoursPaySalesMarginDesired Output
Steve Smith56 hours467.65
Mon16/11/202009:00:0017:00:00Client 1TS 344208.2113.5CS1CS1-WK865.6810842.32Steve Smith
Tue17/11/202009:00:0016:00:00Client 2TS 344238.2113.5CS2CS2-WE757.4794.537.03Steve Smith
Tue17/11/202020:00:0008:00:00Client 3TS 344158.2113.26CS3CS1-WK1298.52159.1260.6Steve Smith
Fri20/11/202020:00:0008:00:00Client 4TS 344138.2113.26CS4CS2-WE1298.52159.1260.6Steve Smith
Sun22/11/202009:00:0015:00:00Client 5TS 344239Sunday BasicSunB14.5CS5CS1-WK6548733Steve Smith
Sun22/11/202020:00:0023:59:00Client 6TS 3177756HRS5089Sunday BasicSunB14.01CS6CS2-WE3.9835.8555.8119.96Steve Smith
Sun22/11/202023:59:0008:00:001Client 7TS 3177756HRS5088.2114.01CS7CS1-WK7.0257.6198.340.7Steve Smith
Claire Williams44 hours364.39Client 8
Mon16/11/202020:00:0008:00:001Client 9TS 341428.2113.01CS9CS1-WK1190.31143.1152.8Claire Williams
Thu19/11/202020:00:0008:00:001Client 10TS 341428.2113.01CS10CS2-WE1190.31143.1152.8Claire Williams
Fri20/11/202020:00:0008:00:001Client 11TS 341428.2113.01CS11CS1-WK1190.31143.1152.8Claire Williams

you'll need to use appropriate format cells for Date, Start and Finish columns because as I said before your table is not a proper 1NF type
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Good Morning. I ran the code you kindly supplied but all I got was "Error" on every row line in the new column that was added via this script

I also changed the column types as you suggested
 
Last edited:
Upvote 0
test M on your source from here
StaffDateStartFinishBreakClientTimesheetCommentPay-HrPay-NamePay-CodeSales-HrSales-NameSales-CodeMultiplierHoursPaySalesMargin
Steve Smith56 hours467.65
Mon16/11/202009:0017:00Client 1TS 344208.2113.5CS1CS1-WK865.6810842.32
Tue17/11/202009:0016:00Client 2TS 344238.2113.5CS2CS2-WE757.4794.537.03
Tue17/11/202020:0008:00Client 3TS 344158.2113.26CS3CS1-WK1298.52159.1260.6
Fri20/11/202020:0008:00Client 4TS 344138.2113.26CS4CS2-WE1298.52159.1260.6
Sun22/11/202009:0015:00Client 5TS 344239Sunday BasicSunB14.5CS5CS1-WK6548733
Sun22/11/202020:0023:59Client 6TS 3177756HRS5089Sunday BasicSunB14.01CS6CS2-WE3.9835.8555.8119.96
Sun22/11/202023:5908:001Client 7TS 3177756HRS5088.2114.01CS7CS1-WK7.0257.6198.340.7
Claire Williams44 hours364.39Client 8
Mon16/11/202020:0008:001Client 9TS 341428.2113.01CS9CS1-WK1190.31143.1152.8
Thu19/11/202020:0008:001Client 10TS 341428.2113.01CS10CS2-WE1190.31143.1152.8
Fri20/11/202020:0008:001Client 11TS 341428.2113.01CS11CS1-WK1190.31143.1152.8

use this to copy data
cpy.png
 
Upvote 0
I tried it and it Works!! So clearly there has to be something different in my data. I will investigate but any suggestions welcome
 
Upvote 0
I don't know your original data so I can't help
the best way will be suggestion from third line of post#7

remember that Power Query is case sensitive so ABC is not the same as abc
check data against unwanted spaces in headers
 
Upvote 0
the column names are completely different then in your example which was not representative
Expression.Error: The field 'Staff' of the record wasn't found.
Details:
Column1=Alton Zulu
Column2=
Column3=56 hours
Column4=467.65
Column5=
Column6=
Column7=
Column8=
Column9=
Column10=
Column11=
Column12=
Column13=
Column14=
and so on...
 
Upvote 0
But what about the Column headers? Does that not get picked up in the formula?
 
Upvote 0
No, column names are defined in the Source step taken from the source table. You cannot use free-style with Power Query

I think you should read this
 
Upvote 0
try
Power Query:
// Query1
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    FD = Table.FillDown(Table.AddColumn(Source, "Custom", each if [Column1] <> "" and [Column2] = null then [Column1] else null),{"Custom"}),
    Result = Table.RemoveColumns(Table.AddColumn(FD, "Staff Name", each if [Column1] = [Custom] and [Column2] = null or [Column2] = "Date" then null else [Custom]),{"Custom"})
in
    Result
with source data you posted in excel file

see this
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,112
Members
452,302
Latest member
TaMere

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