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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
eurenergy
Frequent Visitor

How to avoid using "hard coded" column names in my M code?

Hi all,

 

I recently spoke with a consultant who is very proficient in using Power BI. He mentioned that his #1 rule was to avoide using hard coded column names in his M code. I understand what he means as Power BI is very sensitive when it concerns column names.

 

But how can this be a #1 rule when I think its best to use column names when doing something as simple as changing the data types? You have to adjust data types at some point and by doing that you already have hard coded column names in your M code.

 

Kind regards,

1 REPLY 1
Anonymous
Not applicable

Hi @eurenergy ,

 

You can replace hard-coded column references with dynamic references.

For more detailed information, please refer to the following links:

Solved: Replace hard coded column reference with dynamic r... - Microsoft Fabric Community

How to Handle Dynamic Columns using M query in Power BI | by Datasciencedaemon | Medium

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.