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
Anonymous
Not applicable

Extrat text from long text without trucante word

Hi Dears,

 

I need to display around the first 600 characters of a long text field but the left function truncate the word sometimes.

 

How can I get left part of a long text but get the last full word after a certain position.

 

Best regards,

 

Augusto

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

hi @Anonymous 

 

you can try something like this

someColumn =
VAR _currentString =
    CALCULATE ( SELECTEDVALUE ( 'Table1'[Column1] ) )
VAR _rightPartOfString =
    RIGHT ( _currentString; LEN ( _currentString ) - 600 )
VAR _firstSpace =
    SEARCH ( " "; _rightPartOfString ) - 1
RETURN
    LEFT ( _currentString; 600 + _firstSpace )

 

This code expands the left function to the first space after character number 600.

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

View solution in original post

6 REPLIES 6
sturlaws
Resident Rockstar
Resident Rockstar

hi @Anonymous 

 

you can try something like this

someColumn =
VAR _currentString =
    CALCULATE ( SELECTEDVALUE ( 'Table1'[Column1] ) )
VAR _rightPartOfString =
    RIGHT ( _currentString; LEN ( _currentString ) - 600 )
VAR _firstSpace =
    SEARCH ( " "; _rightPartOfString ) - 1
RETURN
    LEFT ( _currentString; 600 + _firstSpace )

 

This code expands the left function to the first space after character number 600.

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Anonymous
Not applicable

Hi Surla,

 

I'm facing a challange yet. When the long text has less than 600 characters.

 

Could you please help me!

 

Thanks,

 

Augusto

someColumn =
VAR _currentString =
    CALCULATE ( SELECTEDVALUE ( 'Table1'[Column1] ) )
VAR _rightPartOfString =
    RIGHT ( _currentString; LEN ( _currentString ) - 600 )
VAR _firstSpace =
    SEARCH ( " "; _rightPartOfString ) - 1
RETURN
    IF (
        LEN ( _currentstring ) <= 600;
        _currentstring;
        LEFT ( _currentString; 600 + _firstSpace )
    )
Anonymous
Not applicable

Hi Dear Sturla,

 

Last night I tried the same approach as you posted above and got trhe same error message.

 

"An argument of function 'RIGHT' has the wrong data type or has an invalid value."

 

Thanks for your attention,

 

Augusto

try this

someColumn =
VAR _currentString =
    CALCULATE ( SELECTEDVALUE ( 'Table1'[Column1] ) )
VAR _rightPartOfString =
    IF (
        LEN ( _curentstring ) <= 600;
        BLANK ();
        RIGHT ( _currentString; LEN ( _currentString ) - 600 )
    )
VAR _firstSpace =
    IF ( ISBLANK ( _rightPartOfString ); 0; SEARCH ( " "; _rightPartOfString ) - 1 )
RETURN
    IF (
        LEN ( _currentstring ) <= 600;
        _currentstring;
        LEFT ( _currentString; 600 + _firstSpace )
    )

 

Anonymous
Not applicable

Hi Dear Sturla,

 

You save me a lot of effort to get to a measure likes you provided.

 

Your solution works perfectly.

 

Thanks a lot. 

 

Augusto

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.