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
ViorelCa
Helper I
Helper I

Power Query - Extract an Existing Column Name and put it in a new Custom Column

Dear Colleagues,

 

I did not find a solution for a simple problem:

 

Create a new custom column whose only content should be the name of an existing column in that Table.

 

Many thanks!

Viorel

1 ACCEPTED SOLUTION

OK in that case your custom column's formula should be

= List.First(Table.ColumnNames(#"Insert Previous Step Here"))

...for whatever the previous step was. I'm going to guess it's #"Renamed Columns" or #"Changed Type" or something like that.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

15 REPLIES 15
radoslaw85
New Member

Hi there,
im looking for something similiar,
I will be creating multilanguage solution in power query, so im looking for API's

For API's I got what I need, but im strugling to get Current Column Name.

Imagine 4 columns: pl, it, es, fr.
 Now I would need a "simple" function that would retrive column name of the column it resides in. i.e
if my formula resides in column name pl, it would retrive its name which is pl
if my formula resides in column name es, it would retrive its name which is es

Can some1 help?

KHorseman
Community Champion
Community Champion

Which column name? Short of you typing in the name of the column, how is the query supposed to determine which column's name to use?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Sorry, let's say we have Column A, ColumnB and Column C.

 

I want to make a new conditional column (D) that is filled with this text: "Column A"

 

Many thanks!

Viorel

Go to Add Column, hit the Custom Column button and in the formula box type

 

= "Column A"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Is there a function that extracts the name, something like Comun. Name ("Column A")?

I'm not sure why you would want to extract the text from the column header if you already are referring to the column by its name. Wouldn't you expect your hypothetical formula Column.Name("Column A") to return "Column A"? Why not just make a column that contains the text "Column A"? Why would you need to extract the same text you're already typing in?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I did this and it fills the new clumn with the content of the Column A (which I do not want) and not with the name of Column A (Which is "Column A").

 

I know this scenario seems stupid, but this is the format of a report that I have to transform :

 

I have multiple reports whose name of the first column "Column A" is the name of a Brand, so for each brand I have to do a transformation and the only place where I have the name of the Brand is in The name of the Column A, therefore I have to extract it dynamically.

You must have typed

= [Column A]

That's not what I said to do.

= "Column A"

As for your scenario where you will have to extract the name of a column that you don't know the name of, I refer you to my original question. How is the query supposed to know which column to extract the name of if you can't refer to it by name?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I know its name, it's the first column and its name is "Sunny" as in the example above (for the other reports the name is different).

 

I just have to fill a new column with that name, but dynamically, not with ="Sunny", as each report has a different column name corresponding to each Brand.

That still doesn't answer my question. If you can't refer to it by name, how do you know which column to use? Is it literally the first column on the left? Is it always the third? Could it change positions based on which report you're in?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




It is always the first column, and after I get its name (the name of the Brand) I will change it with the proper name (P&L Category), therefore in the new Custom Column I have to remain with the name of the Brand.

OK in that case your custom column's formula should be

= List.First(Table.ColumnNames(#"Insert Previous Step Here"))

...for whatever the previous step was. I'm going to guess it's #"Renamed Columns" or #"Changed Type" or something like that.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Many thanks, @KHorseman , it works like a charm!

 

I remain indebted to you!

 

Kind regards,

Viorel

Is it always literally the first column on the left that you want the name of?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




SunnyDateValueNew Column Windy Date Value New Column
sales5/5/2012   5,000Sunny sales5/5/2012    6,000Windy 
cost5/7/2012   7,000Sunny cost5/7/2012    9,000Windy 

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.