Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello,
I am newer to PBI / Power Query, and new to this community (this is my very first post, so please excuse if this is not the right forum or if this has already been answered).
I am trying to have my column name(s) be dynamically updated based on the current year. For instance, rather than have the title "Current Year" below, I would like for it to say 2021.
I created a query for today's date:
= DateTime.Date (DateTime.LocalNow())
But when I try and reference that query
#"Renamed Columns" = Table.RenameColumns(#"Added Custom1",{{"Current Year", Date.Year(DateToday) }})
I get the following error:
Any input would be appreciated!
Solved! Go to Solution.
I think you can use a different function:
Table.TransformColumnNames(#"Added Custom1",
(colName as text) as text => Text.Replace(colName, "Current Year", Text.From(Date.Year(DateTime.LocalNow ()))))
I may be a little cruel but I think you have to have a go first.
Also be careful with this strategy. You might think you want column headings with different years but this isn't usually a good data storage idea in powerbi. You can always use a matrix visual to display different years.
There are exceptions, of course.
I'm also not convinced that this is dynamic column titles in Power Query is indeed an ideal strategy.
What I was originally looking to accomplish is to build a table in Power BI that has some static columns defining a given product, and then some dynamic columns (2021, 2022, etc.) that show the sales for that product in a given year. I can't dynamically name a measure to be based on the current year, so was thinking of doing something in Power Query.
Anyhow, thanks for the tips.
I think you can use a different function:
Table.TransformColumnNames(#"Added Custom1",
(colName as text) as text => Text.Replace(colName, "Current Year", Text.From(Date.Year(DateTime.LocalNow ()))))
Thank you, HotChilli! One other question. How would that function above be modified if I wanted to have another column for the CurrentYear + 1 (i.e. 2022) and so forth?