DAX Function error – An argument of function ‘LEFT’ has the wrong data type or has an invalid value
Today I was working in SSAS Tabular Mode for SQL Server 2012.
What my goal was, was to remove version numbers from Products. This was so that instead of having the following below in a report:
- Microsoft .Net Framework 1.x
- Microsoft .Net Framework 2.x
- Microsoft .Net Framework 3.x
- Microsoft .Net Framework 4.x
I would have one name instead:
- Microsoft .Net Framework
I was using the DAX Left Function, and nested inside the Left Function I was getting the count of Characters to find out where the “.x” was.
Here is an example of my DAX Function”
=LEFT([ProductName],FORMAT(SEARCH(“.x”,[ProductName],1,-1),0)-3)
This was then giving me the error:
An argument of function ‘LEFT’ has the wrong data type or has an invalid value
At the time I did not realize that in my DAX Syntax for the Search Function I had said if it is not found then give it the value of -1. So SSAS Tabular was indeed correct in giving me the above error.
In order to fix this it was simply adding the IfError DAX Function in order to get it to work:
=IFERROR(LEFT([ProductName],FORMAT(SEARCH(“.x”,[ProductName],1,-1),0)-3),[ProductName])
Now in my PowerView Report it is showing just the Specific Products and not their Version Numbers, thereby making the report look a lot better and less cluttered.
OMG, I have searching for this answer and thank God I found your page.
Hi there
Your comment REALLY made me laugh. Thanks for letting me know, always great to hear that my blog posts help!
Thank you for the precise resolution of this error! Saved me some time.
Thanks for the kind words!
This post is already 10 years old, yet still helping DAX newbies today. Thank you!
That is fantastic to hear, thanks Jun!
Unblieveable, your post is already 10 years ago, and now it help me(I am from China).
My problem is when I use LEFT(ReleasedProductsV2[SearchName],FIND(“_”,ReleasedProductsV2[SearchName],1,0)) then it will works fine.
But if I need -1, use LEFT(ReleasedProductsV2[SearchName],FIND(“_”,ReleasedProductsV2[SearchName],1,0)-1), then will have this error.
Now I fixed this issue according to your post. Thank you:)
Hi Zoe,
That is so cool to hear that it is still helping people 🙂