web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / inconsistent value typ...
Power Apps
Answered

inconsistent value type when returning results from arguments of 'decision' functions

(0) ShareShare
ReportReport
Posted on by 26

Power Apps Authoring Version: 3.22022.31

 

I've discovered that for functions 'making a decision' to return results from its arguments (particularly the If and Switch functions), the value type of the returned result does not always agree with that of the argument's result.  In fact, only the result from the 1st argument determines the value type for all other arguments' results.

 

Consequentially, if the function decides to return an argument's result that cannot be converted to the value type of the 1st argument's result, the function returns null/blank. If the argument's result can be converted, the function returns the converted result (never the original result from the argument).

 

Consider the variable blnDecision in either function of the following examples.

 

 

If(blnDecision, 5, "hi"); Switch(blnDecision, true, 5, false, "hi")

 

When blnDecision is true, each function returns 5. When blnDecision is false, each function returns null/blank.

 

 

 

If(blnDecision, "hi", 5); Switch(blnDecision, true, "hi", false, 5)

 

When blnDecision is true, each function returns hi. When blnDecision is false, each function returns 5 (a string, not a number).

 

This inconsistency doesn't seem to be documented anywhere & needs to be fixed. I use decision functions to sort my tables, and I'm unable to sort by number (only sorts by string).

 

***[EDIT]***

Accepted solution attests that this is not erroneous behavior; it's by-design.  The value type of results returned by functions are evaluated on the first execution pass, not every pass.  You're stuck with whatever value type you have in a function's 1st argument for all other arguments.

 

As for my if/switch logic that undesirably passes numbers as strings into the Sort functions, I'll just be concatenating leading 0s to said numbers, formatted in equal character length.  That way they sort as 1,2,3,4,5,6,7,8,9,10,11,12,etc. and not 1,10,12,13,14,15,16,17,18,19,2,20,21,22,etc.

Categories:
  • TheRobRush Profile Picture
    11,128 Moderator on at

    What is this 'decision' and where are you pulling it from? Is this something unique to Model-Driven apps or something? Have not seen it before but all my apps are Canvas based

  • louiehummv Profile Picture
    26 on at

    It's just an example.  I was attempting to demonstrate the functions' behavior.

  • louiehummv Profile Picture
    26 on at

    And this is within a Canvas app.

  • TheRobRush Profile Picture
    11,128 Moderator on at

    In your specific example, these would be meant to be store in say a label, or a text box etc. A formula has to always have the same data type in it (kind of like you cannot send a text value to a number column in sharepoint. So whatever it has as first item sent to it sets its type.

     

    The reason you see an inconsistency is the order of the two in each.

    If the data is set to a number value first, then that labels type will now be number. If you try to submit the number "hi" to it it will try to convert it to a number, but since hi is not a number it just put nothing

     

    If the number is set to a string first, then the second option is a number it will just drop the number in as a string, because strings CAN be numbers.

     

    This isn't an error it's just how the data works. (To see what I mean you can place "" around your 5 and both will now behave same.

     

    Sorts can be done with both Values and Strings, so would need more info on your specific situation to help with that.

  • louiehummv Profile Picture
    26 on at

    A label or textbox only accept strings (numbers are converted internally), and a string can be converted to a number via the Value() function if the string only contains a number.

     

    But that's beside my point.  My if/switch examples are intended for use as arguments to the Sort() function, which accepts numbers or strings.  This issue, however, is preventing numbers from passing & being sorted as numbers 1,2,3,4,5,6,7,8,9,10,11,12, etc.  They inevitably get sorted as strings 1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,etc..

  • louiehummv Profile Picture
    26 on at

    Actually, the if/switch functions present this issue regardless of what other function arguments I use them in.  So I can't even code a workaround.

  • TheRobRush Profile Picture
    11,128 Moderator on at

    What does the user click to determine the sorting method, and where is the data being displayed, In a gallery? and is the datasource sharepoint? If datasource is sharepoint does the button user presses change column it is sorted by, or the direction (asc/desc) only? The column of numbers that gets sorted (if in splist) can you verify that the column is of the number type and not single line of text?

  • louiehummv Profile Picture
    26 on at

    I can respectfully assure you that none of those questions matter.  If you enter either of my if/switch examples as the formula for the text property of... let's say, a label, you'll observe what I have.

  • TheRobRush Profile Picture
    11,128 Moderator on at

    .

  • louiehummv Profile Picture
    26 on at

    Much appreciated.  It looks like I need to submit this problem to another channel.. but I figured to try here in case someone knew a workaround I wasn't aware of.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard