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
ChemEnger
Advocate IV
Advocate IV

Add Prefix from one column to another in place

I have two columns in a table, named Heading and Prefix.  I am trying to add the Prefix in a row to the Heading column in the same row, in place (rather than add a merged column with Table.CombineColumns, delete & rename etc.)

 

I have tried using the TransformColumns command:

Table.TransformColumns(#"Expanded Albumin Prefixes", {{"Heading", each [Prefix] & _, type text}})

 but get a 'We cannot apply field access to the type Text' error:

ChemEnger_0-1633511340912.png

(Start date is the row value in the Heading column)

I have also tried

Text.From([Prefix])

and

Record.Field(_, "Prefix")

but get the same error.

This feels like it should be easier!  What's most annoying is that I can very easily add a column (Table.AddColumn) with exactly what I need 😠

 

Edit:  The reason I am trying to achieve this is I am bringing in data from an Excel workbook with multiple worksheets and I can have duplicate [Heading]s - I need to differentiate them by adding the [Prefix]

2 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @ChemEnger ,

 

Select you prefix field, then ctrl+click your heading field.

Go to Transform tab > Merge Columns.

 

For reference, this should generate the following code if no delimiter is specified:

 

Table.CombineColumns(
  previousStep,
  {"Prefix", "Heading"},
  Combiner.CombineTextByDelimiter("", QuoteStyle.None),
  "newColumnName"
)

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

CNENFRNL
Community Champion
Community Champion

Simple enough

= Table.ReplaceValue(Source, each [Heading], each [Prefix] & [Heading], Replacer.ReplaceText, {"Heading"})

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

9 REPLIES 9
CNENFRNL
Community Champion
Community Champion

Simple enough

= Table.ReplaceValue(Source, each [Heading], each [Prefix] & [Heading], Replacer.ReplaceText, {"Heading"})

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL I was definitely over-thinking it!  This is indeed 'Simple enough' and worked well, thank you.

BA_Pete
Super User
Super User

Hi @ChemEnger ,

 

Select you prefix field, then ctrl+click your heading field.

Go to Transform tab > Merge Columns.

 

For reference, this should generate the following code if no delimiter is specified:

 

Table.CombineColumns(
  previousStep,
  {"Prefix", "Heading"},
  Combiner.CombineTextByDelimiter("", QuoteStyle.None),
  "newColumnName"
)

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks @BA_Pete.  Unfortunately, this will create a new combined column (newColumnName in your example) and I will then need to delete the two original columns & rename the new column, but I think this is the only way to get what I need.

 

I was trying (hoping!) to do this in one step (TransformColumns) rather than three (CombineColumns- RemoveColumns-RenameColumns)

 

Simon

Hi @ChemEnger ,

 

No, this will not add any new columns. It will turn your two original columns into one single column with a new name that you choose for it to have.

If you're doing it via the GUI rather than manually coding, thn make sure you go to Merge Columns on the Transform tab, not the Add Column tab.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi @BA_Pete,  Apologies for my misunderstanding - changing newColumnName for the original Heading did the trick, basically replacing the old column with the updated version.

 

Simon

Yes, and removing your [prefix] column at the same time as you implied you didn't want to have to delete it afterwards.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




watkinnc
Super User
Super User

Have you tried:

 

 each [Prefix] & [Heading], type text}})

 

--Nate 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Hi @watkinnc,

 

I have now 😉  Same error I'm afraid.  If I hard-type the [Prefix] part as say "123" then the error moves on to the [Heading] part of the command.

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