Forum Discussion
DeepakNarayan
6 years agoRegular Visitor
How to rename column name as current Date dynamically?
Hi, I want to rename a column name as current Date/current Year Month. Could anybody help me on this? Thanks, Deepak Narayan
- 6 years ago
Try the below.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtFTSUTJVitUhgmOElWMB5BgaEMuzQOPEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Year = _t, #"Value " = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Value ", Int64.Type}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type", { { "Year", let currentDateTime = DateTimeZone.LocalNow(), currentYear = Number.ToText( Date.Year( currentDateTime ) ), currentMonth = Date.MonthName( currentDateTime ) in currentYear & "-" & currentMonth } } ) in #"Renamed Columns"Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
GokilaRaviraj
1 year agoHelper II
Hi
I Have a table with different columns , Sep-CFY, Oct-CFY and so till Dec-NFY.
In this table i am showing current month + remaining months of the year + next year all the months.
How to rename this CFY and NFY dynamically with current and next years for all the columns. Or can this be done in visual dynamically ?
Could any one pls help me with this ?
dufoq3
1 year agoCommunity Champion
Hi GokilaRaviraj, check this:
Before
After
v1
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WslTSUTI0ABGGIMIIRAAxiDYGYhMgNgViMyA2B2ILIMbQEhsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sep CFY" = _t, #"Oct CFY" = _t, #"Nov CFY" = _t, #"Dec CFY" = _t, #"Jan NFY" = _t, #"Feb NFY" = _t, #"Mar NFY" = _t, #"Apr NFY" = _t, #"May NFY" = _t, #"Jun NFY" = _t, #"Jul NFY" = _t, #"Aug NFY" = _t, #"Sep NFY" = _t, #"Oct NFY" = _t, #"Nov NFY" = _t, #"Dec NFY" = _t]),
CFY_NFY_ToYears = Table.TransformColumnNames(Source, each
if Text.Contains(_, "CFY") then Text.Replace(_, "CFY", Text.From(Date.Year(DateTime.FixedLocalNow()))) else
if Text.Contains(_, "NFY") then Text.Replace(_, "NFY", Text.From(Date.Year(DateTime.FixedLocalNow())+1))
else _ )
in
CFY_NFY_ToYears
v2
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WslTSUTI0ABGGIMIIRAAxiDYGYhMgNgViMyA2B2ILIMbQEhsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sep CFY" = _t, #"Oct CFY" = _t, #"Nov CFY" = _t, #"Dec CFY" = _t, #"Jan NFY" = _t, #"Feb NFY" = _t, #"Mar NFY" = _t, #"Apr NFY" = _t, #"May NFY" = _t, #"Jun NFY" = _t, #"Jul NFY" = _t, #"Aug NFY" = _t, #"Sep NFY" = _t, #"Oct NFY" = _t, #"Nov NFY" = _t, #"Dec NFY" = _t]),
CFY_NFY_ToYears = Table.TransformColumnNames(Source, each
Text.Combine(List.ReplaceMatchingItems(
Text.Split(_, " "),
{ {"CFY", Text.From(Date.Year(DateTime.FixedLocalNow()))},
{"NFY", Text.From(Date.Year(DateTime.FixedLocalNow())+1)} } ), " ") )
in
CFY_NFY_ToYears
- GokilaRaviraj1 year agoHelper II
- dufoq31 year agoCommunity Champion
You're welcome.