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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Viraj1995
Regular Visitor

Dynamic Column Name (M/PowerQuery) Difficulty

Hi all,

 

I am importing many files (with the same structure from a folder). These files automatically append to each other.

 

I required to change  one of the column names based on it's index position. (as when new files are added to the folder I can't be certain the same file is going to be taken as the first file. This could lead to the column header name to being different.

 

= Table.RenameColumns(#"Promoted Headers",{{Table.ColumnNames(#"Promoted Headers"){28}, "--1"}})

I succesfully changed the column header name. Everything is good up until this point! 

 

However, if the column name is already --1. (The name I am trying to change to) PowerBI will return an error saying:

 

Expression.Error: The field '--1' already exists in the record.
Details:
Name=--1
Value=

 

I considered using a conditional formula inside of this where I would say If = -1, take the previous query. This isn't working and even if it is, I need to replicate this rename column for 5 columns. I can't take the previous query because it depends on which ones worked.

 

Sorry If this isn't clear, I can try clarify if the question again.

 

Thank you

1 ACCEPTED SOLUTION

Solution:
When you import fikes from Share point a sample file is created. You can set which file you like to be selected as your first query.

I can now ensure my first query containta the relevant headers 🙂

(For the if statement, I still cant set the word as it will say you already have this word)

View solution in original post

2 REPLIES 2
TeigeGao
Solution Sage
Solution Sage

Hi @Viraj1995 ,

Could you please tell us what's the problem you meet when using the if function?

Best Regards,

Teige

Solution:
When you import fikes from Share point a sample file is created. You can set which file you like to be selected as your first query.

I can now ensure my first query containta the relevant headers 🙂

(For the if statement, I still cant set the word as it will say you already have this word)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.