Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Problem using conditional logic based on values in multi-select field

(1) ShareShare
ReportReport
Posted on by 64
I am using the Customize Forms functionality with Power Apps for a SharePoint List.  I want to make a field ("Type") required if one of the selections for a multi-select ("Request") is 'Move'.  I have been able to make the field required when "Request" is single choice. However, when using a multi-select field the formula seems to be based on the last value selected. 
 
For the Required element("Type" field), my formula is 
DataCardValue13.Selected.Value = "Move"
 
Possible values for DataCardValue13 are Move and Clean.  
The field shows as required when DataCard values are set to Move OR both Clean and Move, but NOT when the DataCard values are set to both Move and Clean. 
 
Does the formula need to be different somehow?  I was hoping to be able to use a 'contains' or 'includes' operator instead of '=', but that does not seem to be available. 
 
I am new to Power Apps and using it to customize a SharePoint List form is slightly different than using PowerApps as a standalone app. Hopefully this is the correct forum
 
Thank you!
  • Verified answer
    LessCodePaths Profile Picture
    LessCodePaths 100 on at
    Problem using conditional logic based on values in multi-select field
    The first issue is probably related to different formulas in Visible property for label and entry field.
    Could you check it - Both should have the Visible property 
     
    ​"Clean" in DataCardValue13.SelectedItems.Value
    ​
     
     
    If you are using a form, instead of setting the Visible property for each control separately you can use DataCard Visible property and make whole DataCard visible/hidden.
     
    I suppose you have this setup:
     
    Set Visible property as follows:
    1. lbl_CleaningType.Visble = true
    2. dcv_CleaningType.Visible = true
    3. CleaningType_DataCard2.OnVisible = 
    "Clean" in DataCardValue13.SelectedItems.Value
     
     
    Second question:
    Choices('Moving and Cleaning Requests'.Request) vs Choices(Tickets.Types)
     
    It should be fine, sine I used different datasource (SharePoint list) in my example.
    Your datasource is 'Moving and Cleaning Requests' and mine Tickets.
    Similarly your choice column is called Request and mine Types
     
    I hope this will work :)
    L.
     
     
  • tverticchio Profile Picture
    tverticchio 64 on at
    Problem using conditional logic based on values in multi-select field

    Closer... 
     
    Now the labels for Cleaning Type and Move Type show up appropriately, but not the data entry field. 
     
     
     
    Also a question.  In your example below you have DataCardValue13 items property to:
    Choices(Tickets.Types)
     
    I have:
    Choices('Moving and Cleaning Requests'.Request)
     
    Does that matter? 
     
     
     
  • Suggested answer
    LessCodePaths Profile Picture
    LessCodePaths 100 on at
    Problem using conditional logic based on values in multi-select field
    Hi tverticchio,
     
    thanks for sharing additional information.
    I have tried it myself
     
    1. Created new column called "Types" as choice column:
     
     
    2. Set  DataCardValue13 items property to
    Choices(Tickets.Types)
     
    3. Changed visible of the labels this way (I added reference to "Value" column):
    "Clean" in DataCardValue13.SelectedItems.Value
    "Move" in DataCardValue13.SelectedItems.Value
     
    It is working now:
     
     
    The reason is that the structure of Choices() is always:
    [
       { 
          Value: "",
          Id: 0
       }
    ]
    so you have to refer to the right column.
     
    Let me know if it works :)
     
    L.
  • tverticchio Profile Picture
    tverticchio 64 on at
    Problem using conditional logic based on values in multi-select field
    I am using the option from Lists to Customize forms with Power Apps, and the values for the choices are coming from the List, so things look a little different than what you are showing below. 
    I have: 
     
    Then I set the Visible property on both Cleaning Type Data Card and Moving Type Data Cart to what you suggested:
    "Move" in DataCardValue13.SelectedItems (Similar for the data card for Cleaning Type)

    The Items property on DataCardValue13 is:
    Choices('Moving and Cleaning Requests'.Request)
     
    When I run, the field does not show at all, regardless of the Request (which is related to DataCard13.
     
    Sure seems like it should work, but alas, it does not... 
     
    Thanks for sticking in with me to try to figure this out. 

     
  • LessCodePaths Profile Picture
    LessCodePaths 100 on at
    Problem using conditional logic based on values in multi-select field
    Hi,
     
    sorry for late respnse.
    The problem is maybe datacource for combobox.
    What looks Items property for DataCardValue13 like?
     
    I have this setup:
    3 fields
    - Combobox
    - Clean type label
    - Move type lablel
     
     
    Combobox is called DataCardValue13 as yours.
    Items property:
    [
        {
            Value: "Clean"
        },
        {
            Value: "Move"
        }
    ]
     
    Visible property of MoveType label:
    "Move" in DataCardValue13.SelectedItems
     
    Visible property of CleanType label:
    "Clean" in DataCardValue13.SelectedItems
     
    It works this way:
     
    a) When combobox is blank:
     
    b) when "Clean" is selected:
     
    c) when "Move" is selected:
     
    d) when both are selected:
     
     
    I think is should work, maybe the issue could be Items property on DataCardValue13.
    Could yo share it?
     
    L.
     
  • tverticchio Profile Picture
    tverticchio 64 on at
    Problem using conditional logic based on values in multi-select field
    I am trying to do conditional logic to hide/display and make required other fields.  DataCard 13 allows multi-select.  Choices are Move and Clean.  There are two other fields (Move Type and Clean Type).  Move Type should be required and visible if DataCard13 includes/contains Move.  Clean Type should be required and visible if DataCard13 includes/contains Clean.  
     
    I have the required property on the Clean Type DataCard set to 
    If("Clean" in DataCardValue13.SelectedItems, true,false)
     
    As I play with the values in DataCard13, neither Move Type or Clean type are required. 
     
    Hopefully this explanation of what I am trying to do makes sense.  Thank you for your help. 
  • Suggested answer
    LessCodePaths Profile Picture
    LessCodePaths 100 on at
    Problem using conditional logic based on values in multi-select field
    What do you want to archive? Which property do you want to affect?
    My suggestion should help you to check if field is required.
    It should be used for example on "Save" button this way (Button.OnSelect):
    If(
        "Move" in DataCardValue13.SelectedItems,
       //check if some required fields are blank or not
       If(
          IsBlank(RequiredField.Text),
          //warning message if required field is blank
          Notify("Fill in required fields",NotificationType.Warning),
          //procees save - required fields are filled
          SubmitForm(Form1)
       )
       ,
       //save without checking required fields
       SubmitForm(Form1)
    )
    L.
  • tverticchio Profile Picture
    tverticchio 64 on at
    Problem using conditional logic based on values in multi-select field
    Thank you for your response.  Unfortunately, I tried your solution, and it did not work.  I tried both versions of the syntax and in my testing the field never showed as required.  
  • LessCodePaths Profile Picture
    LessCodePaths 100 on at
    Problem using conditional logic based on values in multi-select field
    Hi,
     
    have you tried to use "in" operator?
    I think it should looks like:
    If("Move" in DataCardValue13.SelectedItems, true, false)
    or simply
    ​"Move" in DataCardValue13.SelectedItems
    
    ​
    It should work...
     
     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,495

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,822

Leaderboard