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

Help with DAX function LEFT and a dynamic number of characters

I have a column named BinMax which format is text. I'd like to create a calculated column extracting all but the last two chracters of this string. Say, for BinMax="212", I'd like to get "2" as a return. For "1212", I'd like to get "12".

I tried:

LEFT(
[BinMax]
LEN([BinMax] - 2)
)

 

but got error:

ERROR.png

 

 

 

 

 

 

When I try LEN([BinMax] - 1) it works.

 

What seemed so simple has already taken me hours trying to solve it. What am I missing here?

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 

please try

NewColumn =
IFERROR ( LEFT ( [BinMax], LEN ( [BinMax] - 2 ) ), BLANK () ) 
then filter for the blanks to see which rows are causing the error 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks @tamerj1 , I had zeros in the column, so LEN of any string - 2 equals negative, which results in error. Thanks for opening my eyes to the other rows in the column 🙂

tamerj1
Super User
Super User

Hi @Anonymous 

please try

NewColumn =
IFERROR ( LEFT ( [BinMax], LEN ( [BinMax] - 2 ) ), BLANK () ) 
then filter for the blanks to see which rows are causing the error 

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.

Top Solution Authors