Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

Posted on by 266

Hello everyone,

 

I have 2 dropdowns columns

Unit Make and Unit Model

Unit Make

A
B
C
D
E
F
G
H
I
J

and Unit Model

(should show up or auto selected if once Unit Make is selected)

for A
MZ

 

for B
T110
T220

 

for C
F200
F400
F600

 

for D
500
600

 

for E
MU600

 

for F
C6400

 

for G
5000

 

for H
330

 

for I
Act

 

for J
MD8

 

I made my canvas app(form) from SharePoint list(external data).
How can I make formula for above requirement.

 

I would be thankful for the help.

  • FnuMeenu Profile Picture
    FnuMeenu 266 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

    @MarkBandR Thanks much for the detailed explanation. I appreciate your kind help!

    The example B is working perfectly fine.

    ___________________________________________________

    For example A (would like to make it work also for my knowledge) -

    I changed SharePoint list to Multiselect for the particular column. It removes all errors except 2 errors - 

     

    mtsts_0-1718386392607.pngmtsts_1-1718386415031.png

     

     

     

  • Verified answer
    MarkRahn Profile Picture
    MarkRahn 801 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

    Hi @mtsts 

     

    I am wondering if maybe I misunderstood the initial question. I made the following assumptions:

    1. The user would select the "Make". The "Make" field is setup to only allow a single value to be chosen.
    2. Once the user selects "Make", the "Unit Model" is set. The "Unit Model" is set up to allow multiple values to be selected. It is NOT a single selection field.

    Example A based on past information provided.

    If "Make" is "C", then "Unit Model" should be set to "F200", "F400", and "F600". It would be set to all three of those values.

     

    This is what the code I provided does.

     

    If instead you are looking for,

    When a User selects the "Make", the list of available choices for "Unit Model" should be limited to a subset of the total choices.

     

    Example B:

    If "Make" is "C", then the available choices for "Unit Model" should be limited to "F200", "F400", and "F600". The user would select ONE of those available values.

     

    If you are looking for Example A, then your "Unit Model" field is probably NOT set to allow multiple choices. If you look at your field in SharePoint, it should be set to:

    MarkBandR_1-1718378729832.png

    If you change it, you will need to Refresh the SharePoint List in your Power App to get it to pickup the change. If you are still having errors after you do this, you should copy your code for the DefaultSelectedItems to NotePad, delete the Unit Model Data Card, and re-add it to the Form so that Power Apps picks up the SharePoint Field correctly as a Multi-Choice field. Then paste back in your DefaultSelectedItems code.

     

    IF you are looking for Example B, then you should set the "DefaultSelectedItems" back to "Parent.Default" and set the "Items" property of the "Unit Model" dropdown to just the "Switch" part of your code. This will limit the choices available for "Unit Model" based on the "Make".

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up.

  • FnuMeenu Profile Picture
    FnuMeenu 266 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

    @MarkBandR Thanks much for helping. Here is my code. Giving me errors. 

    mtsts_0-1718375823535.png

    mtsts_3-1718375971757.png

     

     

     

    mtsts_1-1718375911560.pngmtsts_2-1718375933644.png

     

     

    I tried with UnitModel also. It is giving me same errors - 

    mtsts_4-1718376445073.png

     

  • Shravyashree_01 Profile Picture
    Shravyashree_01 174 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

    Hi @mtsts , You can use the below code in the Onchange and Onselect properties of the Unit Make dropdown

     

    Set (VarUnitMake,Self.Selected.Value);

     

    Now, in the Items property of UnitModel use, 

     

    Switch (VarUnitMake, "A",["MZ"],"B",["T110","T220"],"C",["F200","F400","F600"])

     

    and so on..

    Let me know if this helps ! 

    Please click Accept as solution 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 Thumbs Up.

  • Verified answer
    MarkRahn Profile Picture
    MarkRahn 801 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

    Hi @mtsts 

     

    You've got a lot going on there. You have an "If(" that is not connected to anything. You have "UnitModel1" and "UnitModel" in the formula.

     

    Taking what you provided, the following worked for me after duplicating the changes you made to the choices for Make and UnitModel:

    Coalesce(
     Parent.Default,
     Switch(
     DD.Selected.Value,
     "Ftry",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "M"
     ),
     "Kenw",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "T7" Or Value = "T8" Or Value = "T9"
     ),
     "Fouo",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "F5" Or Value = "F6" Or Value = "F7"
     ),
     "Pete",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "58" Or Value = "48"
     ),
     "Inte",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "M07"
     ),
     "Ciot",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "C00"
     ),
     "Dote",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "500"
     ),
     "Hno",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "38"
     ),
     "Ster",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "Ara"
     ),
     "Ma",
     Filter(
     Choices([@'New Service Write Up'].UnitModel),
     Value = "M7"
     )
     )
    )

     

    The UnitModel field had to be setup as a Multi-select Choice field for "Coalesce" to work.

     

    So if I chose "Kenw" for "Make", it would show:

    MarkBandR_0-1718314935155.png

    All of the available Choices are still in UnitModel:

    MarkBandR_1-1718314977097.png

     

    If this has you going in the right direction, can you give a Thumbs Up?

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up.

     

  • FnuMeenu Profile Picture
    FnuMeenu 266 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

    @MarkBandR Yes I am also looking to make a cascading set of drop downs where the choice from the first dropdown determines the available choices in the second dropdown.

     

    Can you share the code for this as well.

    ________________________________________________________________________________________________

     

     

    And I tried the later part code - 

    Coalesce(
    Parent.Default,
    If(
    Switch(
    DD.Selected.Value,
    "Ftry",
    Filter(Choices([@'New Service Write Up'].UnitModel1),Value = "M"),

    "Kenw",
    Filter(Choices([@'New Service Write Up'].UnitModel1), Value = "T7" Or Value = "T8" Or Value = "T9"),


    "Fouo",
    Filter(Choices([@'New Service Write Up'].UnitModel),Value = "F5" Or Value = "F6" Or Value = "F7"),


    "Pete",
    Filter( Choices([@'New Service Write Up'].UnitModel), Value = "58" Or Value = "48"),


    "Inte",
    Filter(Choices([@'New Service Write Up'].UnitModel),Value = "M07"),


    "Ciot",
    Filter(Choices([@'New Service Write Up'].UnitModel), Value = "C00"),


    "Dote",
    Filter(Choices([@'New Service Write Up'].UnitModel), Value = "500"),


    "Hno",
    Filter(Choices([@'New Service Write Up'].UnitModel), Value = "38" ),

    "Ster",
    Filter(Choices([@'New Service Write Up'].UnitModel), Value = "Ara"),

    "Ma",
    Filter( Choices([@'New Service Write Up'].UnitModel), Value = "M7")
    ),
    )
    )
    )

     

     

    It is giving me error - 

    mtsts_0-1718310586294.pngmtsts_1-1718310616911.png

     

     

     

  • MarkRahn Profile Picture
    MarkRahn 801 on at
    Re: how to make auto selection for options in dropdown 2 column based on drop down 1 in canvas app

     

    It is unclear if you are looking to make a cascading set of drop downs where the choice from the first dropdown determines the available choices in the second dropdown

    Or

    if you are looking to set the second dropdown based on the choices in the first dropdown.

     

    I assumed the latter.

     

    This might work for the "DefaultSelectedItems" property of your "Unit Model" dropdown. This assumes your first dropdown is named "dd_Make".

    Coalesce(
     Parent.Default,
     If(
     EditForm1.Mode = FormMode.New,
     Switch(
     dd_Make.Selected.Value,
     "A",
     Filter(
     Choices([@'YourListHERE'].Model),
     Value = "MZ"
     ),
     "B",
     Filter(
     Choices([@'YourListHERE'].Model),
     (Value = "T110" Or Value = "T220")
     ),
     "C",
     Filter(
     Choices([@'YourListHERE'].Model),
     (Value = "F200" Or Value = "F400" Or Value = "F600")
     )
     //Repeat for other choices
     )
     )
    )

    This will only execute the Switch statement if the Form is in FormMode.New. Remove that line if you don't need it.

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up.

    Hi @mtsts 

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,532

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,050

Leaderboard