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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
AnandNamburi
Helper III
Helper III

M code to add a column new column from SQL DB

Hi All,

 

I have a table called "Service" and it was imported in to Power Bi. After importing, backend team has modified 2 coulmns in the same table. So when I opened the dashboard it is throwing error that the columns are not avaiable.

 

I'm looking for an effective way to handle this type of issues.  

 

The approach I'm thinking is to delete the renamed columns and add the modified columns as a new column. But I'm nit able to do that.

 

Can anyone suggest the M code to add a column from SQL DB

 

 

Thanks In Advance

3 REPLIES 3
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Can you post your m code? There are various ways to solve this issue. For example, you can rename back those columns to old names before those are used in your code so no futher code modification is required (but it depends upon your situation)

Hi Vijay,

 

The M code is below

 

let
Source = Sql.Database("Anand092.database.windows.net", "Anand092"),
edwmrtanand_service = Source{[Schema="edwmrtanand",Item="service"]}[Data],
#"Renamed Columns" = Table.RenameColumns(edwmrt_service,{{"Clm", "Claim"}, {"Hlth", "Health"}, {"Srvc", "Service"}})
in
#"Renamed Columns"

 

In the table is service.

Suppose if a new column say "Column 1" gets added then how can I accomodate it in M code

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

If Column1 is a new addition to the table, then unless you use it in your code, it will not impact you. For example, in your code, if you add a new Column1 and  when you refresh your query, it will not have any impact as you are not using Column1 anywhere.

But suppose Column1 was already existing and its name is changed to Column_1 then, in Rename Columns add this also {"Column_1", "Column1"}, then whereever you are referring to Column1 in your code, that will not be impacted.

Having said that I am not sure if it answers your questions as I feel that I am missing something. Let me know what is that.

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.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.