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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
aallman
Helper I
Helper I

Issue with Value() function converting string to number

I am using a switch formula to simplify and bucket a column of mixed numeric and text values. The goal is to simplify values that are numeric with text to just the number. (For example, I have these values in the column: "2", "2g", "2 g"  and I want all of them to be returned as "2".) There are some values in the column that do not have any numbers such as "dg" and "ph". I used the formula ISERROR(VALUE([mycolumn])) within my switch formula to return a value of "Other" for these values. 

 

The problem is with one single row that has the value "2a". This does NOT return as an error within the VALUE() function. It actually returns a value of 0.0833333 for a reason I can't figure out.  Is "a" some stored variable? What is going on and how can I fix it??

 

aallman_2-1659028308712.png

 

aallman_1-1659028294331.png

 

 

3 REPLIES 3
tamerj1
Super User
Super User

Hi @aallman 
It is not simple simple as you may think it is. However, might not be so coplex but relly depends on the shape of your data. Please provide a reasonable and relevent sample of data to work with. 
On the other hand a power bi column can only contain data of one data type. In case of error you can return blank not a string.

The issue is that it is not returning an error like it should. ISERROR(VALUE("2a")) should return TRUE but it returns FALSE. See the attached screenshots. 

here is a small sample of the values in the column I am working with: 

aallman_0-1659031025174.pngaallman_1-1659031043168.png

This column is a string column and the column I am creating is also a string column. I did some replace fucntions to remove blank spaces and "g" and "G" (because those are the most common units attached to the end of my numeric values). 

Hi @aallman 
Please follow these steps

1.png2.png3.png

Numbers = 
SELECTCOLUMNS (
    UNION (
        GENERATESERIES ( 0, 9, 1 ),
        { "." }
    ),
    "Digit",
    [Value]
)
Value = 
VAR String = 'Table'[MyColumn]
VAR Length = LEN ( String )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = ADDCOLUMNS ( T1, "@Letter", MID ( String, [Value], 1 ) )
VAR T3 = FILTER ( T2, [@Letter] IN VALUES ( Numbers[Digit] ) )
RETURN
    VALUE ( CONCATENATEX ( T3, [@Letter],, [Value], ASC ) )

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors