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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
parry2k
Super User
Super User

Power Query M - Change proper case for first row of the table

how can I can transform (proper case) of all column in first rows of the table in Power Query 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Example for the first 2 rows:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nD18fFX0lEK9w/ycVGK1YlWSi1LLaosycjMSwcKp2XmpdqDhfNSy4H8ovxyMC8xL78kI7UIJhILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    Typed = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    ProperCaseFirst2Rows = Table.TransformColumns(Table.FirstN(Typed,2),{}, Text.Proper) & Table.Skip(Typed,2)
in
    ProperCaseFirst2Rows
Specializing in Power Query Formula Language (M)

View solution in original post

8 REPLIES 8
MarcelBeug
Community Champion
Community Champion

Example for the first 2 rows:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nD18fFX0lEK9w/ycVGK1YlWSi1LLaosycjMSwcKp2XmpdqDhfNSy4H8ovxyMC8xL78kI7UIJhILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    Typed = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    ProperCaseFirst2Rows = Table.TransformColumns(Table.FirstN(Typed,2),{}, Text.Proper) & Table.Skip(Typed,2)
in
    ProperCaseFirst2Rows
Specializing in Power Query Formula Language (M)

@MarcelBeug

 

Are  you using {} empty list (highligted in red) to account for the second argument in Table.TransformColumns () ? Or there is another logic here ?  Is this by the way an empty list or a full list since function applies to all the values ? 

 

 

Table.TransformColumns(
        Table.FirstN(Typed,2),
         {},   
         Text.Proper
)

 

 

Thanks

 

 

The {} is an empty list.

 

In this case it means that no transform operations are supplied as the second argument.

 

Instead, the 3rd argument is supplied, being the default Transformation function. i.e. the default operation that applies to the columns for which no specific transform operations are specified in the second argument.

Specializing in Power Query Formula Language (M)

@MarcelBeug

 

Thanks for the answer. 

I have a question on  transformOperations  what arguemnts does it take in its list? 

In the example, provided in the formula reference Table.TransformColumns second argument (The list of transformOperations to run) converts text column to number 

 

So, when we see transformOperations should we assume that it takes   {column to change, function} ? ( or as it shown in the example {"A", Number.FromText} )

 

Table.TransformColumns(      
   Table.FromRecords({[A="1", B=2], [A="5", B=10]}),      
   {"A", Number.FromText}
) equals Table.FromRecords({[A=1,B=2], [A=5,B=10]})

 

Argument Description

tableThe Table to modify.
transformOperationsThe list of transformOperations to run.
optional defaultTransformationThe default table transformation.
optional missingFieldMissing field value.

Almost.

 

There is another, optional, third argument, in which you can specify the resulting column data type.

 

This information is not available in any docuentation I could find, but if you use standard menu options on the Transform tab, then the generated code includes that third argument, e.g. after chosing menu option Date - Month - End Of Month:

 

= Table.TransformColumns(Typed,{{"Date", Date.EndOfMonth, type date}})

 

I'm not sure if that third argument is always present in generated code via the Transform tab.

Specializing in Power Query Formula Language (M)

@MarcelBeug

 

Thank you very much. 

Just one last note. Are we wrapping the list of transformOperations as a list or list of lists (one set of curly brackets or two)?  

 

 

= Table.TransformColumns(Typed,{{"Date", Date.EndOfMonth, type date}})

 

Thanks again.

It is a list of lists, 2 curly brackets: you can specify transformations for multiple columns, and each specification has 2 or 3 items.

 

{{"Column1", operation1},{"Column2", operation2}, etcetra}

Specializing in Power Query Formula Language (M)

Thanks that did it. Cheers!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors