Skip to main content

Notifications

Power Apps - Power Apps Pro Dev & ISV
Suggested answer

Error message converting text to value

Like (1) ShareShare
ReportReport
Posted on 22 Dec 2024 14:16:33 by 2
Can anyone provide any guidance to how to convert text to a number without getting an error message. This is the If statement I am using. I am comparing 2 numbers from 2 different text controls and attempting to change the fill color of a circle. Everything works properly but I still get an error when the app loads that says "the value 'text' cannot be converted to a number."
 
   If(
        Value(CountActual_4.Text) > Value(CountMinimum_4.Text),
        Color.Green,
        If(
            Value(CountActual_4.Text) = Value(CountMinimum_4.Text),
            Color.Gold,
            Color.Red
        )
    )
 
 
  • WarrenBelz Profile Picture
    WarrenBelz 144,563 on 04 Jan 2025 at 07:57:27
    Error message converting text to value
    @Inogic is correct - that one slipped my mind when I initially responded - I was too focussed on another possible cause.
  • Suggested answer
    Inogic Profile Picture
    Inogic 848 on 03 Jan 2025 at 11:22:28
    Error message converting text to value
    Hi,
     
    The error occurs because the Value function is being applied to the Text property of your controls, but when the app loads, the Text property may initially be blank or contain non-numeric values. This causes the Value function to throw an error since it cannot convert a blank or invalid text to a number.

    To resolve this issue, you can use the IsBlank or IsNumeric function to handle these cases gracefully. Here is the updated formula:

    If(
        IsNumeric(CountActual_4.Text) && IsNumeric(CountMinimum_4.Text),
        If(
            Value(CountActual_4.Text) > Value(CountMinimum_4.Text),
            Color.Green,
            If(
                Value(CountActual_4.Text) = Value(CountMinimum_4.Text),
                Color.Gold,
                Color.Red
            )
        ),
        Color.Gray // Default color if the input is not numeric
    )
     
    Hope this helps.
     
    Thanks!
    Inogic Professional Services: Power Platform/Dynamics 365 CRM
    An expert technical extension for your techno-functional business needs
    Drop an email at crm@inogic.com 
    Service: https://www.inogic.com/services/ 
    Tips and Tricks: https://www.inogic.com/blog/ 
  • WarrenBelz Profile Picture
    WarrenBelz 144,563 on 31 Dec 2024 at 23:01:29
    Error message converting text to value
     
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • WarrenBelz Profile Picture
    WarrenBelz 144,563 on 23 Dec 2024 at 08:14:39
    Error message converting text to value
    Firstly try this ,but also paste it in all at once rather than typing
    With(
       {
          _Actual: Value(CountActual_4.Text),
          _Min: Value(CountMinimum_4.Text)
       },
       If(
          _Actual > _Min,
          Color.Green,
          _Actual = _Min,
          Color.Gold,
          Color.Red
       )
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • scalca Profile Picture
    scalca 230 on 23 Dec 2024 at 05:42:20
    Error message converting text to value
    What's the initial value of the text fields ? 
    probably when it loads the app the initial value is some text which cannot be converted and after that you load get some values from a source. 
    you could implement an exception handling mechanism to catch the error using IfError()

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,563

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,396

Leaderboard
Loading started