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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / I try to update a fiel...
Power Apps
Answered

I try to update a field by using a value range

(1) ShareShare
ReportReport
Posted on by 261

Hello 

I am trying to get a filed updated by value ranges:

 

/*
Update item in column ApproverGroup
*/
If(
    Value(TextInput2.Text) <= 2000,
    Patch(
        'NEW-BRAZIL-Main',
        LookUp(
            'NEW-BRAZIL-Main',
            myID = varID,
            {
                ApproverGroup: {Value: "NoApprover"}
            }
        ),
        If(
            Value(TextInput2.Text) <= 10000,
            Patch(
                'NEW-BRAZIL-Main',
                LookUp(
                    'NEW-BRAZIL-Main',
                    myID = varID,
                    {
                        ApproverGroup: {Value: "AccountManager"}
                    }
                ),
                If(
                    Value(TextInput2.Text) > 10000,
                    Patch(
                        'NEW-BRAZIL-Main',
                        LookUp(
                            'NEW-BRAZIL-Main',
                            myID = varID,
                            {
                                ApproverGroup: {Value: "Director"}
                            }
                        )
                    )
                )
            )
        )
    )
)
;
 
 
I tried also to get the sum of the Library field by using the code:
 
/*
Update item in column ApproverGroup
*/
If(
Sum(Gallery1.AllItems,ValorAjuste) <= 2000,
Patch(
'NEW-BRAZIL-Main',
LookUp(
'NEW-BRAZIL-Main',
myID = varID,
{
ApproverGroup: {Value: "NoApprover"}
}
),
If(
Sum(Gallery1.AllItems,ValorAjuste) <= 10000,
Patch(
'NEW-BRAZIL-Main',
LookUp(
'NEW-BRAZIL-Main',
myID = varID,
{
ApproverGroup: {Value: "AccountManager"}
}
),
If(
Sum(Gallery1.AllItems,ValorAjuste) > 10000,
Patch(
'NEW-BRAZIL-Main',
LookUp(
'NEW-BRAZIL-Main',
myID = varID,
{
ApproverGroup: {Value: "Director"}
}
)
)
)
)
)
)
)
;
 
 
The problem is, that the field is not updating the ApproverGroup.
Is there any idea available, I try to AVOID to use flow, which is more simple but not what I want to achieve...
 
Thanks in advance 😉
 
Cheers
Michael
Categories:
I have the same question (0)
  • Verified answer
    Michael E. Gernaey Profile Picture
    53,360 Super User 2025 Season 2 on at

    Can you please do me a favor @MD2024   and re-paste your code into Code Snipps </> so its easier to consume.

    And I am going to focus on the one question for the title.

     

    How is this code triggered? a button, onchange event what?

     

    You said it doesn't update, which I assume means it doesn't hit any of these If places.

    1. Does this happen in Dev, Test, Prod, all of the above?

     

    If it happens in dev then do this

    Above your If put

    Trace("Above If Statement - " & TextInput2.Text);
    
    This will tell you for 100% what its trying to do
    
    Now in each section of the if's add a Trace statement so see if it hits any of them
    
    Trace("<2000")' above the Value line
    Trace("<=10000") again above its sections valuel line
    
    Once you do this, if its in Dev, then hit the Stethescope and run Monitor.
    Repro the issue
    Go to the Monitor Tab in the Browser
    
    Type Trace for the filter
    see which ones get triggered,
    
    Should take 5 minutes tops.
    


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • ivan_apps Profile Picture
    2,187 Moderator on at

    How are you defining "varID"?  that seems like the key to your issue, you're doing a lookup to it on all scenarios. Do your choice values also not have spaces in between? if it doesn't match what's configured, i believe sharepoint will create the new choice value for you, but your filters may be hard-coded with spaces like "No Approver".

     

    You also don't have to nest IF statements, you can simplify like this:

    If(
        Value(TextInput2.Text) <= 2000,
        Patch(),
        Value(TextInput2.Text) <= 10000,
        Patch(),
        Value(TextInput2.Text) > 10000,
        Patch(),
        [else condition]
    )
  • MD2024 Profile Picture
    261 on at

    Hello Michael

    Thanks for the Trace() information, thats helpful in some circumstances otherwise I needed to test every variation to find ou whats working or not.

    The trigger is a Button onSelect.

    My solution on the en which was working is a Switch()

     

     

    Switch(true,
    Value(TextInputSum.Text) <= 2000, //FIRST CONDITION
    Patch(InventoryAdjust_Main,LookUp(InventoryAdjust_Main,Identifier=DataCardValue24.Text),{ApproverGroup:{Value:"NoApprover"}});
    // Requester don#t need approval <= 2000
    Patch(InventoryAdjust_Main,LookUp(InventoryAdjust_Main,Identifier=DataCardValue24.Text),{Status:{Value:"Approved"}});
    
    Value(TextInputSum.Text) >2000 And Value(TextInputSum.Text) <=10000, //SECOND CONDITION
    Patch(InventoryAdjust_Main,LookUp(InventoryAdjust_Main,Identifier=DataCardValue24.Text),{ApproverGroup:{Value:"AccountManager"}});
    
    Value(TextInputSum.Text) >10000, //SECOND CONDITION
    Patch(InventoryAdjust_Main,LookUp(InventoryAdjust_Main,Identifier=DataCardValue24.Text),{ApproverGroup:{Value:"Director"}});
    );

     

     

    The idea with:   Sum(Gallery1.AllItems,ValorAjuste) was still not working.

     

    But thanks a lot for your hint !!!

    Cheers

    Michael

     

     

  • MD2024 Profile Picture
    261 on at

    Hello ivan_apps

    Thanks for the hint, makes it easier 😉

     

    Cheers

    Michael

  • ivan_apps Profile Picture
    2,187 Moderator on at

    I’m confused, did you wrap your IF statement in a Switch with the only case being ‘true’ and it somehow started working??

  • Michael E. Gernaey Profile Picture
    53,360 Super User 2025 Season 2 on at

    Thats a shame as it shouldn't take that long to test the scenarios and would have helped out to tell you exactly what was broken but hey go the long way, what do I know...... oh wait..

  • MD2024 Profile Picture
    261 on at

    😁No, why I would do that... I replaced the old IF with a switch, thats how it works 👍

  • MD2024 Profile Picture
    261 on at

    Hello FLMike

    It was not working for me with the Trace() as you told me: 

    Trace("<2000")' above the Value line
    Trace("<=10000") again above its sections valuel line


    I get no output with sense in the monitored trace.

    Or I dont get any output:

     

    onSelect  Button 

    -----------------------

    Set(varTest,"");
    If(

    Trace(<= 2000),
    Value(TextInput1.Text) <= 2000,
    Set(varTest,"smaller then 2000"),

    Trace(<= 10000),
    Value(TextInput1.Text) <= 10000,
    Set(varTest,"higher 2000 less + equal 10000"),

    Trace(> 10000),
    Value(TextInput1.Text) > 10000,
    Set(varTest,"higher then 10000")
    )

     

    And I like to see the variable value as well (with other debugger you can do)...,

    so not really working for me ;(

     

    Cheers

    Michael

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard