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 / Patching Collection Us...
Power Apps
Answered

Patching Collection Using LookUp not working, and other Collection Questions

(0) ShareShare
ReportReport
Posted on by 71
Three Questions Here:
 
1. How do I initialize a collection without getting a blank row? Usually I do this but I don't think this is right
         ClearCollect(CollectionName, Column1:"",Column2"") or ClearCollect(CollectionName, Column1:Blank(),Column2:Blank())
2. Presently an issue I have is that I have established this collection (it will be on Start or OnVisible but I am using OnChange of a dropdown for testing efficiency):
           ClearCollect(Criteria_Weights, ForAll(Choices([@'SP_List'].'Level 1 Criteria'),{Criteria: ThisRecord.Value, Level:""}))
 
This works fine. But I am trying to patch to it onchange of a different dropdown using this formula, and i do not receive any errors but it also doesn't patch). 
             Patch(LookUp(Criteria_Weights, Criteria=Level1Criteria), {Level: "Level 1"})
3. This may be best on another post, but  I am hoping to use this collection to force unique selections across 5 dropdowns which works sort of. Presently in order of thiese dropdowns I have the Items property set to
Filter(Choices([@'SP_List'].'Level 3 Criteria'), ThisRecord.Value<>Level1_Value.Selected.Value&&ThisRecord.Value<>Level2_Value.Selected.Value).
 
 
Which works when selected sequentially, but if the user doubles back to make a change, then duplicates can happen. Is there a way to force a reset of the now conflicting other dropdown? Or does anyone have a better way to do this?
 
As always TIA!
 
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    First one a bit clunky, but will work
    ClearCollect(
       CollectionName, 
       Column1: Blank(),
       Column2: Blank()
    );
    Clear(CollectionName)
    Second one you need to specify the target
    Patch(
       Criteria_Weights,
       LookUp(
          Criteria_Weights, 
          Criteria = Level1Criteria
       ), 
       {Level: "Level 1"}
    )
    the last one I need some clarification - this is referencing a couple of other drop-downs, but should dynamically update if they are changed
    Filter(
       Choices([@'SP_List'].'Level 3 Criteria'), 
       Value <> Level1_Value.Selected.Value && 
       Value <> Level2_Value.Selected.Value
    )
    What is it that needs resetting ?
     
    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
  • CU12092006-0 Profile Picture
    71 on at
    @WarrenBelz - Thank you I was missing the target! 
     
    What is the difference between using Blank() and "" when initializing a collection like that?
     
    As for the final bit what I currently have is 5 DataCards linked directly to SP choice columns (all column choices are identical across the 5 columns). 
     
    Level1 Datacard Items: 
    Choices([@'SP_List'].'Level 1 Criteria')
     
    Level 2 DataCard Items: 
    Filter(Choices([@'Collection Planning Form (Draft)'].'Level 2 Criteria'),ThisRecord.Value<>Level1_Value.Selected.Value)
     
    and so on and so forth, which works in a cascading fashion top down, but doesn't eliminate the risk of duplicates if a user goes backwards in the form and changes their answer, so I added the on change to each dropdown to force a reset of the conflicting column (answered my own question):
     
    If(Self.Selected.Value=Level1_Value.Selected.Value,Reset(Level1_Value));
    If(Self.Selected.Value=Level3_Value.Selected.Value,Reset(Level3_Value));
    If(Self.Selected.Value=Level4_Value.Selected.Value,Reset(Level4_Value));
    If(Self.Selected.Value=Level5_Value.Selected.Value,Reset(Level5_Value));
     
    I originally wanted to remove options from the dropdowns if it was used in a different dropdown, but have opted against that because I think it makes edits clunky from a UI standpoint. But before I decided that, I tried: 
     
    OnChange: 
    If(IsEmpty(Self.SelectedItems)=false,
            Set(Level5,Self.Selected.Value);
            Patch(
                Criteria_Weights,
                        LookUp(
                            Criteria_Weights,
                            Criteria = Self.Selected.Value
                        ),
                        {Level: "Level 5", Used: true}
                        ));
     
    If(IsEmpty(Self.SelectedItems)=true,Patch(
       Criteria_Weights,
       LookUp(
          Criteria_Weights,
          Criteria = Level5
       ),
       {Level: Blank(), Used: false}
    ));
     
    Items:
    Filter(Choices([@'Collection Planning Form (Draft)'].'Level 1 Criteria'),LookUp(Criteria_Weights,Criteria=ThisRecord.Criteria, Used)=false)
     
    and that did not work, I suspect that my collections and tables need to be disambiguated but I'm not sure how or where. 
     
    So I think I've avoided needing it for this project, but I'd like to learn how for the future.
     
     
     
     
     
     
     
     
  • Verified answer
    WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    First item, Blank() and "" are two different things - the first is Null (nothing) and the second is an empty string. Actually in your case "" would probably be better as it pre-defines the field as type Text.
    To your other issue, Assuming the choices are all the same across all controls, if you want to dynamically eliminate duplicates in all drop-downs, put a button or icon on the screen and hide it with the OnSelect
    ClearCollect(
       colItems,
       [
          Level1.Selected.Value,
          Level2.Selected.Value,
          Level3.Selected.Value,
          Level4.Selected.Value,
          Level5.Selected.Value
       ]
    )
    Then OnChange of each of your drop-downs (this just saves repeating the code on each control)
    Select(YourButton/IconName)
    Then the Items of all of your drop-downs
    Filter(
        Choices([@'SP_List'].'Level 1 Criteria'),
        !(Value in colItems.Value)
    )
     
    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
  • CU12092006-0 Profile Picture
    71 on at
    @WarrenBelz Thank you I tried something similar to that last one in the item properties of the respective dropdowns so 
     
    Dropdown1 Items Property: 
     
    Filter(Choices([@'SP_List'].'Level 1 Criteria'), Value <> Level2_Value.Selected.Value && Value <> Level3_Value.Selected.Value && Level4_Value.Selected.Value && Level5_Value.Selected.Value)
     
    Dropdown2 Items Property: 
     
    Filter(Choices([@'SP_List'].'Level 2 Criteria'), Value <> Level1_Value.Selected.Value && Value <> Level3_Value.Selected.Value && Level4_Value.Selected.Value && Level5_Value.Selected.Value)
     
     
    And this begets an error that says "This rule creates a circular reference between properties, which is not allowed. A property cannot reference itself or other properties affected by its value."
     
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    Did you try what I posted ? I spent some time on a model verifying it works and it is not similar in concept to your latest post - you will get a circular reference if you have any controls directly or indirectly refer to each other's values, hence the direction I took.
     
    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   
  • CU12092006-0 Profile Picture
    71 on at
    @WarrenBelz Nope you're totally right, I did not follow directions, I'm sorry. That worked, thank you so much , you're a wizard!
     
    Why does it have to be in a button and not just a collection, besides reducing code redundancy? I tried creating a collection then removing options as they were selected but it didn't work, either because of circular logic, or not resetting, or not providing any options at all. My hope was to test this with a stand-in dropdown, then migrate the creation of the ccollection to the OnStart of the app or similar. I thought it was strange because each dropdown is referencing a different (identical) dropdown list.
     
    I've gathered that the "!" in front of something effectively negates/inverses it, right? Nifty.
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    You can but the same code as the button OnChange of all the drop-downs (and not use the button) - the Select statement on the button just saves you some code.
    Yes the !  Function is the same as Not()

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard