Forum Discussion
Replace Column Headers with current dates
- 6 years ago
Hello jcbutts
I recognized that I got you wrong. So week 1 is always the current week.
I fixed this now. Check out this one if it works
let Source = #table ( {"week 1","week 2","week 3","other data","abc","week 52"}, { {"","","","","",""} } ), ColumnNames = Table.ColumnNames ( Source ), TransformWeekInDate = List.Transform ( ColumnNames, (row)=> try if Text.Contains(row,"week") or Text.Contains(row,"Week") then Text.From(Date.AddDays(Date.AddDays( Date.From(DateTime.FixedLocalNow()), Date.DayOfWeek(DateTime.FixedLocalNow())*-1), (Number.From(Text.Replace(row, "week ", ""))-1)*7)) else row otherwise row ), RenameColumnHeader = Table.RenameColumns ( Source, List.Zip({ColumnNames,TransformWeekInDate}) ) in RenameColumnHeaderJimmy
Hi Jimmy,
The code seems to be what I'm looking for. However, when I run it, "week 1"= last week (12/30/19), when it should equal this week (somewhere between 1/5/2020 and 1/11/2020). How do I fix that?
Also, what are the steps to incorporate into my own code? I apologize in advance....I'm very new at this. I tried taking everything in your code below the "source" line and putting it in at the bottom of my code. The result is a small matrix with a link that says "Table". I click on that link and it reopens my data.....but the dates aren't changed. Mine looks like this:
let
Source = Excel.Workbook(File.Contents("V:\\Forecast and Inventory Planning_US.xlsx"), null, true),
#"US_Forecast and Inventory Plann_Sheet" = Source{[Item="US_Forecast and Inventory Plann",Kind="Sheet"]}[Data],
#"Removed Top Rows" = Table.Skip(#"US_Forecast and Inventory Plann_Sheet",1),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true])
in
#"Promoted Headers"
Any direction is appreciated.
Hello jcbutts
I recognized that I got you wrong. So week 1 is always the current week.
I fixed this now. Check out this one if it works
let
Source = #table
(
{"week 1","week 2","week 3","other data","abc","week 52"},
{
{"","","","","",""}
}
),
ColumnNames = Table.ColumnNames
(
Source
),
TransformWeekInDate = List.Transform
(
ColumnNames,
(row)=> try
if Text.Contains(row,"week") or Text.Contains(row,"Week") then
Text.From(Date.AddDays(Date.AddDays( Date.From(DateTime.FixedLocalNow()), Date.DayOfWeek(DateTime.FixedLocalNow())*-1), (Number.From(Text.Replace(row, "week ", ""))-1)*7))
else
row
otherwise
row
),
RenameColumnHeader = Table.RenameColumns
(
Source,
List.Zip({ColumnNames,TransformWeekInDate})
)
in
RenameColumnHeader
Jimmy