roodie84
New member
- Joined
- Nov 20, 2020
- Messages
- 1
- Reaction score
- 0
- Points
- 0
- Excel Version(s)
- 2019
Hi,
I am trying to clean my Column Header Name, so that:
1. Any header name that is combined will be separated from the first capital letter by "space".
2. The header name will be in Proper Case, except if the word are all capitalise.
Example is as below.
Column Header Name:
First Name
MaintActType
TECO date
FIN Date
ABC indicator
COGS
Created On
to become new and cleaned Column Header Name:
First Name
Main Act Type
TECO Date
FIN Date
ABC Indicator
COGS
Created On
my M Language is as below:
let
But what i get in the end is:
First Name
Main Act Type
TECODate (wrong)
FINDate (wrong)
ABCIndicator (wrong)
COGS
Created On
How can i make this as i wanted? i have tried to figure out the right syntax for 7 hours, but I failed.
Can anybody help, please?
I am trying to clean my Column Header Name, so that:
1. Any header name that is combined will be separated from the first capital letter by "space".
2. The header name will be in Proper Case, except if the word are all capitalise.
Example is as below.
Column Header Name:
First Name
MaintActType
TECO date
FIN Date
ABC indicator
COGS
Created On
to become new and cleaned Column Header Name:
First Name
Main Act Type
TECO Date
FIN Date
ABC Indicator
COGS
Created On
my M Language is as below:
let
Source = Excel.Workbook(File.Contents("C:\RawData\sample.xlsx"), null, true),
#"sample_Sheet" = Source{[Item="sample",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"sample_Sheet", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(#"Promoted Headers", Text.Trim),
#"Split CapitalLetter" = Table.TransformColumnNames(#"Trim ColumnSpace", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")),
#"Remove DoubleSpace" = Table.TransformColumnNames(#"Split CapitalLetter", each Replacer.ReplaceText(_, " ", " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Remove DoubleSpace", Text.Proper),
#"Remove Space" = Table.TransformColumnNames(#"Capitalise FirstLetter", each Text.Remove(_, {" "})),
#"Separate ColumnName" = Table.TransformColumnNames(#"Remove Space", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " "))
in#"sample_Sheet" = Source{[Item="sample",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"sample_Sheet", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(#"Promoted Headers", Text.Trim),
#"Split CapitalLetter" = Table.TransformColumnNames(#"Trim ColumnSpace", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")),
#"Remove DoubleSpace" = Table.TransformColumnNames(#"Split CapitalLetter", each Replacer.ReplaceText(_, " ", " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Remove DoubleSpace", Text.Proper),
#"Remove Space" = Table.TransformColumnNames(#"Capitalise FirstLetter", each Text.Remove(_, {" "})),
#"Separate ColumnName" = Table.TransformColumnNames(#"Remove Space", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " "))
#"Separate ColumnName"
But what i get in the end is:
First Name
Main Act Type
TECODate (wrong)
FINDate (wrong)
ABCIndicator (wrong)
COGS
Created On
How can i make this as i wanted? i have tried to figure out the right syntax for 7 hours, but I failed.
Can anybody help, please?