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
Anonymous
Not applicable

Using Conditional column to return a string and the numbers following it

Hello,

 

Apologies if I don't explain this the best, still a little new to Power BI desktop. So essentially I have a column that has a couple million values, and some of them contain a medcode (i.e. med001, med002...med313) inside a long string of text. So the conditional column I have I set the parameters as if it contains med, return med, if not it returns another column. The issue I am having is I am trying to get it to return the numbers following it as well. I figure I can just add in the 300 rows in the conditional column and filter out each med code specifically, but I just wanted to see if there was a way I could automate it? I've tried having it return "med###" and "med***" hoping that would return the next three numbers but it just returns those characters.

 

Thank you!

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

You can achieve your goal by using Conditional column directly.

I build a sample to have a test.

You can set the parameters as if column1 contains med, return column1, if not it returns another column. 

Result is as below.

1.png

Or you can build a calculated column.

C.Custom = 
IF(CONTAINSSTRING('Table'[Column1],"med"),'Table'[Column1],'Table'[Column2])

Result:

2.png

You can download the pbix file from this link: Using Conditional column to return a string and the numbers following it

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

You can achieve your goal by using Conditional column directly.

I build a sample to have a test.

You can set the parameters as if column1 contains med, return column1, if not it returns another column. 

Result is as below.

1.png

Or you can build a calculated column.

C.Custom = 
IF(CONTAINSSTRING('Table'[Column1],"med"),'Table'[Column1],'Table'[Column2])

Result:

2.png

You can download the pbix file from this link: Using Conditional column to return a string and the numbers following it

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

DataInsights
Super User
Super User

@Anonymous,

 

Try this calculated column:

 

MedCode = 
VAR vMedCodeStartPos =
    SEARCH ( "med", TestMed[Column1], 1, 0 )
VAR vResult =
    IF (
        vMedCodeStartPos = 0,
        TestMed[Column2],
        MID ( TestMed[Column1], vMedCodeStartPos, 6 )
    )
RETURN
    vResult

 





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

Proud to be a Super User!




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.