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
juhoneyighot
Helper II
Helper II

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
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.