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

How to get the Number of Characters from a Column 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_3-1699099382473.png

 

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

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

juhoneyighot_5-1699099674844.png

 

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

Hi @juhoneyighot,

You can try to use following formula to create a calculated column to get the character counts:

charCount =
VAR _path =
    SUBSTITUTE ( 'Table'[Text], "_", "|" )
VAR _suffix =
    PATHITEM ( _path, PATHLENGTH ( _path ) )
VAR replaced =
    SUBSTITUTE ( 'Table'[Text], "_" & _suffix, "" )
RETURN
    LEN ( replaced )

1.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @juhoneyighot,

You can try to use following formula to create a calculated column to get the character counts:

charCount =
VAR _path =
    SUBSTITUTE ( 'Table'[Text], "_", "|" )
VAR _suffix =
    PATHITEM ( _path, PATHLENGTH ( _path ) )
VAR replaced =
    SUBSTITUTE ( 'Table'[Text], "_" & _suffix, "" )
RETURN
    LEN ( replaced )

1.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
lbendlin
Super User
Super User

Does it have to be DAX? You can use the PATH functions for that.  

It's much easier to do in Power Query.

 

Please provide sample data that fully covers your issue. Are there two underscores as the second divider?
Please show the expected outcome based on the sample data you provided.

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.