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
MYDATASTORY
Resolver I
Resolver I

How to check if a string has a certain suffix in a column

Hi

Kindly help with a suggestion on DAX, I have a column(DummyDataCarID) and I would like to check if that column has  hyphen (-)  and suffixes, and if yes then 1 and if no then 0. Please note dummy data has bee used for example.

DummyDataCarID                        Expected answer 

4645-673                                     1

7879-78                                    1

7899-ETW5                                  1

8906                                             0

8780                                             0

 

2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @MYDATASTORY 

Calc column =
VAR posHyphen_ =
    SEARCH ( "-", Table1[CarID], 1, 0 )
VAR anythingAfterHyphen_ =
    IF ( LEN ( Table1[CarID] ) > posHyphen_, 1, 0 )
RETURN
    IF ( posHyphen_ = 0, 0, anythingAfterHyphen_ )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

Pragati11
Super User
Super User

Hi @MYDATASTORY ,

 

You can use the following DAX:

containsVal = IF(CONTAINSSTRING(Table1[CarID], "-") = TRUE(), 1, 0)
 
Replace Table1[CarID] in above DAX with your tablename and column.
 
If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

8 REPLIES 8
Pragati11
Super User
Super User

Hi @MYDATASTORY ,

 

You can use the following DAX:

containsVal = IF(CONTAINSSTRING(Table1[CarID], "-") = TRUE(), 1, 0)
 
Replace Table1[CarID] in above DAX with your tablename and column.
 
If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

 
AlB
Super User
Super User

Hi @MYDATASTORY 

Calc column =
VAR posHyphen_ =
    SEARCH ( "-", Table1[CarID], 1, 0 )
VAR anythingAfterHyphen_ =
    IF ( LEN ( Table1[CarID] ) > posHyphen_, 1, 0 )
RETURN
    IF ( posHyphen_ = 0, 0, anythingAfterHyphen_ )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Thanks to your help, I have tried this seems to work but it does not check if there is suffix after the hyphen basically I also want to check if there is suffix after hyphen which can be 6889-DSG3 OR  6889-454, DAX provides is catching the hyphen but it will need to check if there is suffix after the hyphen. Please note this is dummy data.

Hi @MYDATASTORY 

It would help if you mention who you're answering to. You say "it will need to check if there is suffix after the hyphen". What on earth does that mean exactly? My code checks whether there is something (doesn't matter what) after the hyphen. What do you want to check exactly. A specific suffix? Only DSG3 or 454? Are those the only two suffixes you are interested in (after the hyphen)?? If so:

Calc column =
IF( SEARCH ( "-DSG3", Table1[CarID], 1, 0 )>0 || SEARCH ( "-454", Table1[CarID], 1, 0 )>0,
    1,
    0 )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

 

 

@MYDATASTORY 

 

The idea of previous replied solution is those cells have suffixes always contain a hyphen before the suffix. So you can just check whether a cell contains a hyphen. Please update the sample how is your original data included the suffixes in the cell.


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

VijayP
Super User
Super User

@MYDATASTORY 

Column = IF(CONTAINSSTRINGEXACT('Table'[Text],"-"),1,0)
Create a new column using the above function which gives the result
 
Regards
Vijay Perepa
If this is solution for your Query please mark this a solution and share your Kudoes
also you can watch my Videos on www.youtube.com/perepavijay



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

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.