cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted

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

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: How to rename column name as current Date dynamically?

Hi @DeepakNarayan 

 

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.
Mariusz Repczynski

 

View solution in original post

1 REPLY 1
Super User
Super User

Re: How to rename column name as current Date dynamically?

Hi @DeepakNarayan 

 

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.
Mariusz Repczynski

 

View solution in original post

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Top Kudoed Authors
Users Online
Currently online: 74 members 971 guests
Please welcome our newest community members: