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
teaguejs
Helper II
Helper II

Trying to create new column by combining a string + column value

Hi,

 

I am trying to create a new column by adding "String123 - " to the beginning of the value from another column.

1 ACCEPTED SOLUTION

Hi @teaguejs ,

 

This seems really tricky because PBI tries to apply the code in a query straight from the data source and depending on the data source itself, it either works or doesn't. I'd suggest you fix that column in the source or you create a view to manipulate the string. Another solution could be to you just use Import mode 🙂 Here a pretty lively discussion about your last error message:

 

OLE DB or ODBC error: [Expression.Error] We couldn... - Microsoft Power BI Community

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

9 REPLIES 9
tackytechtom
Super User
Super User

Hi @teaguejs,

 

I have not worked with Direct Query yet, so I tried to read up on it. It seems like it kinda depends on your data source, when you are using Power Query. Have you tried creating the new column in DAX? Does it return the same error message?

 

This seems a great resource that many other threads were referring to:

Using DirectQuery in Power BI - Power BI | Microsoft Docs

Solved: M for Calculated Column in Direct Query Mode - Microsoft Power BI Community

DirectQuery in Analysis Services 2016 - SQLBI

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @teaguejs ,

 

And here a solution in DAX:

tomfox_2-1652125018406.png

Right click on the column and press new column. Here the DAX:

Custom = 
"String123 - " & 'Table'[Column] 

 

Generally, it is better to do such things in Power Query if possible, but since you posted it in here (Desktop), I wasn't sure which one you needed.

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I tried this DAX:

new_column =
"String123 - " & 'table_name'[column_name]


And got this error:
"A single value for column 'column_name' in table 'table_name' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

So I used "new column" rather than "new measure" and it didnd't error out initially, but it did error out when I tried to add that new field to a current table, so close enough for now

The error says:
OLE DB or ODBC error: [Expression.Error] We couldn't fold the expression to the data source. Please try a simpler expression..

Hi @teaguejs ,

 

This seems really tricky because PBI tries to apply the code in a query straight from the data source and depending on the data source itself, it either works or doesn't. I'd suggest you fix that column in the source or you create a view to manipulate the string. Another solution could be to you just use Import mode 🙂 Here a pretty lively discussion about your last error message:

 

OLE DB or ODBC error: [Expression.Error] We couldn... - Microsoft Power BI Community

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I ended up just editing in a CONCAT sql statement in the direct query and that seemed to do the trick, thanks for all your help @tackytechtom 

tackytechtom
Super User
Super User

Hi @teaguejs 

 

Here a solution in Power Query:

tomfox_1-1652124827570.png

 

Here the code

= "String123 - " & [Column]

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Unfortunately I am using "Direct Query" for the data and that step mentions "This step results in a query that is not supported in DirectQuery mode". Any ideas how to achieve the same result while still using direct query?

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.