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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

How to recode Source.Name using M code ?

Hi All

How to recode Value lable for SourceName :-

SI_PM.CSV to PM

SI_SD.CSV to SD

Take the 4 and 5 charater. As i have many file.

Paulyeo11_0-1604115832404.png

https://www.dropbox.com/s/7tk5tqkonpuama4/M%20CODE%20LOAD%20CSV%20FILE%20V002.pbix?dl=0

Above link is my PBI FILE

 

Paul

 

2 ACCEPTED SOLUTIONS
AlB
Community Champion
Community Champion

Hi @Anonymous 

If it's the 4th and 5th characters that you want, you can create a custom column with this code:

=  Text.Middle( [Source.Name], 3, 2)

Then you can delete the original Source.Name column if necessary and rename the newly created column

Or you can use Table.TransformColumns( ) but the option above is probably easier

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

View solution in original post

AlB
Community Champion
Community Champion

@Anonymous 

You asked for a solution in M code, which is what I provided.  In the pic you seem to be trying to do it in DAX. If that is the case, you can create a calculated column with

New col =
MID(Table1[Source Name], 4, 2)

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

View solution in original post

6 REPLIES 6
AlB
Community Champion
Community Champion

Hi @Anonymous 

If it's the 4th and 5th characters that you want, you can create a custom column with this code:

=  Text.Middle( [Source.Name], 3, 2)

Then you can delete the original Source.Name column if necessary and rename the newly created column

Or you can use Table.TransformColumns( ) but the option above is probably easier

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

Anonymous
Not applicable

Hi Sir

I try to use your expression , i get error msg. Can you share with me where go wrong ?

Paulyeo11_0-1604134318173.png

 

AlB
Community Champion
Community Champion

@Anonymous 

You asked for a solution in M code, which is what I provided.  In the pic you seem to be trying to do it in DAX. If that is the case, you can create a calculated column with

New col =
MID(Table1[Source Name], 4, 2)

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

Anonymous
Not applicable

Hi Sir

Thank you it work fine now.

Paul

Anonymous
Not applicable

Thank you AIB.

Anonymous
Not applicable

Hi Sir

Yes for this it is better not using M code. Thank you very much for sharing.

Paul

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors