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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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

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
v-xinruzhu-msft
Community Support
Community Support

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.

 

@v-xinruzhu-msft 

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?

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.