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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
juhoneyighot
Helper III
Helper III

Need help with DAX Formula for the number of characters in a text with a certain condition.

Hello! I am new to PowerBI.

I need to have a calculated column how to get the number of characters from a certain column(JobType_txt). However, there is one condition. Some of the Jobtype_txt dont have a value in # of _ Column. See screenshot below.

juhoneyighot_0-1699185841575.png

 

 

Condition is: If # of _ is " " then Phase_=" " else need a calculation for below requirement. 

juhoneyighot_1-1699185841545.png

 

 

Example: Jobtype_txt: NC 110_Estimates__10NotStarted

The text is divided into

Prefix: NC 110

"_"

Phase_:Estimates_

"_",

Status:10NtotStarted

 

So, I need to have a calculated column the number of characters from Prefix until "Phase_". So from JobType_text: NC 110_Estimates_

 

So the Phase_=17

 

I have this sample Excel formula for this. See screenshot below.

 

 

My problem is I don't know how to convert this to DAX formula.

I hope you can help me on this. 

Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @juhoneyighot 

It seems that you created it as a calculated column, you need to create it as a measure intstead of a calculated column. if you want to create calculated column, you can refer to the following code.

Column = var a=SUBSTITUTE('Table'[_JobType_txt],"_","|")
return IF(NOT(ISBLANK('Table'[#of_])),LEN(PATHITEM(a,1))+LEN(PATHITEM(a,2))+2,0)

Then when you put the field to visual, you need to select 'Don't summarize' 

vxinruzhumsft_0-1699405657124.png

 

Best Regards!

Yolo Zhu

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

5 REPLIES 5
Anonymous
Not applicable

Hi @juhoneyighot 

You can refer to the following measure

Sample data 

vxinruzhumsft_0-1699339702058.png

Measure:

Count_txt =
VAR a =
    SUBSTITUTE ( SELECTEDVALUE ( 'Table'[_JobType_txt] ), "_", "|" )
RETURN
    IF (
        NOT ( ISBLANK ( MAX ( 'Table'[#of_] ) ) ),
        LEN ( PATHITEM ( a, 1 ) ) + LEN ( PATHITEM ( a, 2 ) ) + 2,
        0
    )

Output

vxinruzhumsft_1-1699339782939.png

 

Best Regards!

Yolo Zhu

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

 

@Anonymous 

juhoneyighot_0-1699361113649.png

Here is the entered formula but when I added the field in the visual it has Sum of Phase_

juhoneyighot_1-1699361178213.png

Did I did something wrong?

Anonymous
Not applicable

Hi @juhoneyighot 

It seems that you created it as a calculated column, you need to create it as a measure intstead of a calculated column. if you want to create calculated column, you can refer to the following code.

Column = var a=SUBSTITUTE('Table'[_JobType_txt],"_","|")
return IF(NOT(ISBLANK('Table'[#of_])),LEN(PATHITEM(a,1))+LEN(PATHITEM(a,2))+2,0)

Then when you put the field to visual, you need to select 'Don't summarize' 

vxinruzhumsft_0-1699405657124.png

 

Best Regards!

Yolo Zhu

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

 

pls try this

Count TEXT = 
VAR LenText = LEN(MAX('Table'[_JobType_txt]))
 VAR LenPatch = LEN(PATHITEMREVERSE( SUBSTITUTE(MAX('Table'[_JobType_txt]),"_","|"),1))
 RETURN
 IF( MAX('Table'[#of_]),
LenText - LenPatch ,0)

Screenshot_3.png

Ahmedx
Super User
Super User

Share some data to work with (in a format the can be pasted in an MS Excel file) and show the expected result.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.