Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
newbie74
Frequent Visitor

Removing last characters of multiple columns headers

Dear community,

 

i am trying to remove the last 3 characters of multiple columns' headers.

see my table below - i have 3 characters following the month and year.

 

As i will need to redo the same with different characters at every update, i need to find a way to automatize this in M.

 

newbie74_0-1620910056694.png

 

Many thanks in advance for your help.

 

1 ACCEPTED SOLUTION
FrankAT
Community Champion
Community Champion

Hi @newbie74 

you can do it like this:

 

13-05-_2021_15-44-37.png

 

// Table
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0lXSwYJjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Apr-21_27" = _t, #"May-21_28" = _t, #"Jun-21_29" = _t, #"Jul-21_30" = _t, #"Aug-21_31" = _t, #"Sep-21_32" = _t]),
    #"Demoted Headers" = Table.DemoteHeaders(Source),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Demoted Headers", {{"Column1", each Text.BeforeDelimiter(_, "_"), type text}, {"Column2", each Text.BeforeDelimiter(_, "_"), type text}, {"Column3", each Text.BeforeDelimiter(_, "_"), type text}, {"Column4", each Text.BeforeDelimiter(_, "_"), type text}, {"Column5", each Text.BeforeDelimiter(_, "_"), type text}, {"Column6", each Text.BeforeDelimiter(_, "_"), type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Text Before Delimiter", [PromoteAllScalars=true])
in
    #"Promoted Headers"

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

View solution in original post

3 REPLIES 3
newbie74
Frequent Visitor

Never got the chance to thank you guys for the help!

THANKS A LOT!

FrankAT
Community Champion
Community Champion

Hi @newbie74 

you can do it like this:

 

13-05-_2021_15-44-37.png

 

// Table
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0lXSwYJjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Apr-21_27" = _t, #"May-21_28" = _t, #"Jun-21_29" = _t, #"Jul-21_30" = _t, #"Aug-21_31" = _t, #"Sep-21_32" = _t]),
    #"Demoted Headers" = Table.DemoteHeaders(Source),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Demoted Headers", {{"Column1", each Text.BeforeDelimiter(_, "_"), type text}, {"Column2", each Text.BeforeDelimiter(_, "_"), type text}, {"Column3", each Text.BeforeDelimiter(_, "_"), type text}, {"Column4", each Text.BeforeDelimiter(_, "_"), type text}, {"Column5", each Text.BeforeDelimiter(_, "_"), type text}, {"Column6", each Text.BeforeDelimiter(_, "_"), type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Text Before Delimiter", [PromoteAllScalars=true])
in
    #"Promoted Headers"

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

amitchandak
Super User
Super User

@newbie74 , Unpivot the table.

Then use Text. Start, Text.mid and Text.End to split the date and month

 

if need you can pivot

https://radacad.com/pivot-and-unpivot-with-power-bi

Text.Start, Mid -https://www.youtube.com/watch?v=vky4wPqm0O0

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.