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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
OKgo
Helper IV
Helper IV

DAX help with LEN & SUBSTITUTE

I have a formula that works great in Excel,

IF([@[Assigned]]="","",(LEN([@[Assigned]])-LEN(SUBSTITUTE([@[Assigned]],"ASSIGNED","")))/8"))

 

Example entry from Table[Assigned]:

ASSIGNED_Material ID 123- 600010 - Lot: 4444 (31-Aug-2018), ASSIGNED_Material ID 333- 6023 - Lot: 3133 (31-Aug-2019)

 

LEN count ASSIGNED = 16 characters divided by the amount of letters in ASSIGNED = answer = 2

 

I am struggling with the DAX equivilant

=
IF (
    Table[Assigned] = BLANK (),
    BLANK (),
    (
        LEN ( Table[Assigned] )
            - LEN (
                SUBSTITUTE ( Table[Assigned], "ASSIGNED", BLANK () ) / 8)
            )
    )
)

Tips greatly apprecaited

 

 

1 ACCEPTED SOLUTION

@OKgo,

 

Try:

Column =
IF (
    'Table'[Assigned] = BLANK (),
    BLANK (),
    DIVIDE (
        LEN ( 'Table'[Assigned] )
            - LEN ( SUBSTITUTE ( 'Table'[Assigned], "ASSIGNED", BLANK () ) ),
        8
    )
)





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

5 REPLIES 5
ChrisMendoza
Resident Rockstar
Resident Rockstar

@OKgo,

 

I am having trouble deciphering your column headers and their values. Please format as table or provide datafile sample.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



@OKgo,

 

Try:

Column =
IF (
    'Table'[Assigned] = BLANK (),
    BLANK (),
    DIVIDE (
        LEN ( 'Table'[Assigned] )
            - LEN ( SUBSTITUTE ( 'Table'[Assigned], "ASSIGNED", BLANK () ) ),
        8
    )
)





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Its beautiful! Thank you @ChrisMendoza

OKgo
Helper IV
Helper IV

In early construction of the Dax formula this error popped up from time to time but then dissappeared.
Calculation error in column 'Table[Assigned]" xxxx of type text to type number

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

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.