Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
VistaDee
Frequent Visitor

Check Characters in string in DAX

Hi

 

Im trying to convert a SQL CASE statement to DAX IF . Lets say I have a column of values like:

ProjectCode

D-IREE00215

BADR0022

A-DD1255

 

and part of the query is as follows:

 

CASE

        WHEN LEFT(ProjectCode,4) LIKE '%[a-z]%' AND SUBSTRING(ProjectCode,5,4) LIKE '%[0-9]%'

 

How do I write this in DAX so that the only field returned will be BADR0022

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @VistaDee  ,

Here are the steps you can follow:

1. Create calculated column

flag =
var _1={"A","B","C","D","E","F","G","H","I","J","K","M","L","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
VAR _2={0,1,2,3,4,5,6,7,8,9}
var _5=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],5,1)))
var _6=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],6,1)))
var _7=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],7,1)))
var _8=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],8,1)))
RETURN
IF(LEFT('Table'[column],1) IN _1&&MID('Table'[column],2,1) IN _1&&MID('Table'[column],3,1) IN _1&&MID('Table'[column],4,1) IN _1&&
_5 IN _2 && _6 IN _2 && _7 IN _2 &&_8 IN _2,
'Table'[column],BLANK()
)

2. Result.

v-yangliu-msft_0-1617614675466.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

2 REPLIES 2
Anonymous
Not applicable

Hi  @VistaDee  ,

Here are the steps you can follow:

1. Create calculated column

flag =
var _1={"A","B","C","D","E","F","G","H","I","J","K","M","L","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
VAR _2={0,1,2,3,4,5,6,7,8,9}
var _5=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],5,1)))
var _6=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],6,1)))
var _7=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],7,1)))
var _8=IF(ISERROR(VALUE(MID('Table'[column],5,1))),BLANK(),VALUE(MID('Table'[column],8,1)))
RETURN
IF(LEFT('Table'[column],1) IN _1&&MID('Table'[column],2,1) IN _1&&MID('Table'[column],3,1) IN _1&&MID('Table'[column],4,1) IN _1&&
_5 IN _2 && _6 IN _2 && _7 IN _2 &&_8 IN _2,
'Table'[column],BLANK()
)

2. Result.

v-yangliu-msft_0-1617614675466.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

PhilipTreacy
Super User
Super User

Hi @VistaDee 

 

Download sample PBIX with the following code

 

I understand the SQL code but could you achieve the same thing by checking that the string does not contain a - ?

To create a column n DAX this would be 

 

Column = IF(NOT(CONTAINSSTRING('Table1'[ProjectCode], "-")),'Table1'[ProjectCode])

 

However this is creating a new column in your data model and that might not be what you want as a lot of the column fields will be empty.

If you want to do it a a measure use this

Measure = IF(NOT(CONTAINSSTRING(SELECTEDVALUE('Table1'[ProjectCode]), "-")),SELECTEDVALUE('Table1'[ProjectCode]))

What exactly is the end result you want? A new column? A measure? Or just some code to use elsewhere?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.