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
KBE
New Member

If columnname is already been used then use another columnname

Hello,

 

thought it would be something simple and in my memories I thought it worked already. About 12 month ago I made a query to restructure offered excel formats from different suppliers to a standard format. Now some formats use a columnname with ADRESS and some have three different columnnames with STREET, NUMBER and LETTER and some use both. 

 

if the format was offered with the three column seperate I'm combining them with the columnname ADRESS. Now it happens in occasions two columnames are the same and powerquery gives an error. So to bypass the error I used the following:

 

try Table.AddColumn(#"PreviousStep", "ADRESS", each ([STREET]&[NUMBER]&[LETTER])) otherwise Table.AddColumn(#"PreviousStep", "NOTTHEADRESS", each ([STREET]&[NUMBER]&[LETTER]))

 

Am I missing something why this doesn't work.

 

Thanks in advance!

 

 

 

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

=Table.AddColumn(#"PreviousStep",if List.Contains(Table.ColumnNames(#"PreviousStep"), "ADRESS") then "NOTTHEADRESS" else "ADRESS",each Text.Format("#[STREET]#[NUMBER]#[LETTER]",_))

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

=Table.AddColumn(#"PreviousStep",if List.Contains(Table.ColumnNames(#"PreviousStep"), "ADRESS") then "NOTTHEADRESS" else "ADRESS",each Text.Format("#[STREET]#[NUMBER]#[LETTER]",_))

Thanks a lot! it works and also look like the proper way to do so. Can add this to my repertoire. 

v-jingzhang
Community Support
Community Support

Hi @KBE 

 

I tried your M code, it works well with my sample data as below. 

vjingzhang_0-1675823864824.png

 

One possible cause of error is the data type of three columns. & is used to concatenate Text values. If one value is in other data types (e.g. NUMBER column is in Integer type in below table), it will return error. So please check the data types of columns [STREET], [NUMBER] and [LETTER] in your table. 

vjingzhang_1-1675823981207.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Hello, 

 

thank you for the effort. In the previous step I changed the types, there is probably still something wrong with my doing, but I appriciate the help.

 

Kind Regards,

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.

Top Solution Authors
Top Kudoed Authors