Forum Discussion
jcbutts
6 years agoHelper I
Replace Column Headers with current dates
Hi, I'm new to this: I'm trying to replace column headers with the current week in one column and iterate from there. For example, I have columns that say "week 1", "week 2", "week 3".....et...
- 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
jcbutts
6 years agoHelper I
I tried all of these. For the first solution, I got an error saying the colunmn "Week 1" wasn't found. My actual column header is "Week 1- Mean Forecast" so I modified the code to match (checking a few different iterations for the spacing between the dash and the words) but it all came up with the same error...."Week 1 - Mean Forecast" not found.
For the other two solutions, the code was accepted, but it resulted in a table with one line. The headers were things like "Name" and "Hidden", and the data was just the name of my data file and the type.