Forum Discussion

bartvana's avatar
bartvana
Iron Contributor
Mar 29, 2021
Solved

Power Query Custom Function with IF statement

I made the custom function below in Power query, but results are not what I expect. If I put in 0.1 I get 50 instead of 0, for instance. Must be some stupid mistake or misunderstanding on my part, can anyone tell me what's wrong?

(vGrowth as number) => 
if vGrowth > 1 then 100 
else if vGrowth > 0.5 then 50 
else if vGrowth > 0.2 then 20 
else if vGrowth > -0.2 then 0 
else if vGrowth > -0.5 then -20 
else if vGrowth > -1 then -50 
else -100

 

  • bartvana 

    It works correctly

    function is

    (vGrowth as number) =>
    let result = 
        if vGrowth > 1 then 100 
        else if vGrowth > 0.5 then 50 
        else if vGrowth > 0.2 then 20 
        else if vGrowth > -0.2 then 0 
        else if vGrowth > -0.5 then -20 
        else if vGrowth > -1 then -50 
        else -100
    in result

2 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    bartvana 

    It works correctly

    function is

    (vGrowth as number) =>
    let result = 
        if vGrowth > 1 then 100 
        else if vGrowth > 0.5 then 50 
        else if vGrowth > 0.2 then 20 
        else if vGrowth > -0.2 then 0 
        else if vGrowth > -0.5 then -20 
        else if vGrowth > -1 then -50 
        else -100
    in result
    • bartvana's avatar
      bartvana
      Iron Contributor
      Yes, it does for me now too, very odd. Should've taken a screenshot. When I invoked the function, I got strange results. Thanks for looking into it...

Resources