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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
bpierceaxo
New Member

Custom Column

I am trying to create a Custom Column with data from another column.   I have a column that has 4 digits for the Dept # and I only want to use the first three.   When I use the Left function -

= Table.AddColumn(#"Sorted Rows", "Dept", each LEFT([code], 3))      code is the orginal column name

 

I get the following error message.

Expression.Error: The name 'LEFT' wasn't recognized. Make sure it's spelled correctly.

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @bpierceaxo ,

 

The error occurs because the LEFT function is used in Excel and DAX, but not in the Power Query M language. The correct Power Query function to extract the first characters from a text string is Text.Start.

You can fix the issue by updating your formula to use the correct function. The new formula will get the first three characters from your [code] column and place them in your new Dept column.

= Table.AddColumn(#"Sorted Rows", "Dept", each Text.Start(Text.From([code]), 3))

In this corrected formula, Text.Start replaces LEFT. It's also a good practice to wrap your column name in Text.From(), as shown. This step ensures Power Query treats the column's data as text, which prevents errors if the original column has a number format.

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @bpierceaxo ,

 

The error occurs because the LEFT function is used in Excel and DAX, but not in the Power Query M language. The correct Power Query function to extract the first characters from a text string is Text.Start.

You can fix the issue by updating your formula to use the correct function. The new formula will get the first three characters from your [code] column and place them in your new Dept column.

= Table.AddColumn(#"Sorted Rows", "Dept", each Text.Start(Text.From([code]), 3))

In this corrected formula, Text.Start replaces LEFT. It's also a good practice to wrap your column name in Text.From(), as shown. This step ensures Power Query treats the column's data as text, which prevents errors if the original column has a number format.

 

Best regards,

mdaatifraza5556
Super User
Super User

Hi @bpierceaxo 

Can you please try the below M code ?

= Table.AddColumn(#"Sorted Rows", "Dept", each Text.Start([code], 3), type text)

Screenshot 2025-07-22 192707.png

 


If this answers your questions, kindly accept it as a solution and give kudos.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.