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
cj_sh
Regular Visitor

Finding fix text in the string

I am fetching data from SharePoint list.

 

Requirement:

there is a string, from which I need to find two fix words (AD and PC), and send the finding into a new column.

 

 

1 ACCEPTED SOLUTION

Hi @cj_sh ,

 

You could add if() function to return the results you want.

if
Text.Contains([Column1],"PC")=true
then
[Column1]
else
"Your other result"

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

7 REPLIES 7
mussaenda
Super User
Super User

Have you solved your problem @cj_sh ?

Anonymous
Not applicable

Hi @cj_sh ,

 

The easiest way to achieve this is Conditional Columns in Power Query. 

Please Use Operator as contains or Equal according to your other options.

Please use the attached picture as reference.

 

Best Regards,

Gaurav Raj SinghConditional Column.PNG

mussaenda
Super User
Super User

you can do it on power query or dax

 

in power query, you can create a conditional column and put your condition there.

in dax, you can use containsstring function to find your desired words and use if statement

@mussaenda  Thanks, I don't know why my query editor is not showing ContainsString function among the choices.

 

but I am trying Text.Contains([ColumnName],"AD"),  and it is giving me True/False  whereever AD in the string. 

Now I am getting challenge in value AD in the column instead of True.

 

Can you help me in that.. 

Hi @cj_sh ,

 

The language used in Power Query is M while that in the designer is DAX that's why you can't use CONTAINSTRING in the query editor.  For your requirement, you can try this in DAX:

 

New Column =
//will return blank if both criteria are not met
IF (
    CONTAINSSTRING ( Table[Column], "AD" ) && CONTAINSSTRING ( Table[Column], "PC" ),
    Table[Column]
)

 

 

EDIT:

M is case-sensitive.  That's why you are getting a TRUE/FALSE result instead of just either. You can wrap your column first in Text.Upper before using Text.Contains so it would be something like: 

Text.Contains ( Text.Lower ( [Column] ) )









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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Hi @danextian  ,

 

I think in this situation OR will be the right condition, not AND. 

So in DAX use the below formula,

 

New Column =
//will return blank if both criteria are not met
IF (
    CONTAINSSTRING ( Table[Column], "AD" ) || CONTAINSSTRING ( Table[Column], "PC" ),
    Table[Column]
)

 

Hi @cj_sh ,

 

You could add if() function to return the results you want.

if
Text.Contains([Column1],"PC")=true
then
[Column1]
else
"Your other result"

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

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.