cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Setting a default selected in the combobox

Dear all,

 

I would like to set an IF condition for a Combobox field, which would show a filtered value as the default selected value if Form.Mode = New or parent.default if otherwise.

 

First I set the filter for the available items in the Library Combobox. The library Combobox Items = 

Sort( Distinct( Filter( MTDemoSPList, Factory = cmb_Demo1.Selected.Result), Library),Result,Ascending) which works as expected. 

Then. I have tried the following formula for Library combobox's DefaultSelectedItems, which show no error, but also return no value:

 

If(varFormMode = FormMode.New,
    Distinct(
        Filter(
        MTDemoSPList2,
        Books = cmb_Demo1.Selected.Result
    ).Library
,Parent.Default))

 

 

 Could anyone please advise if there is a logical error in the function above?

2 ACCEPTED SOLUTIONS

Accepted Solutions
RandyHayes
Super User
Super User

@Anonymous 

Choice columns have records with a Value column.  Your formulas are all producing tables that have Result columns.  This will not match.  Comboboxes have to have matching values.

So, since you are using a combobox, your Items property should be changed to the following:

RenameColumns(
    Sort(
        Distinct(
            Filter(MTDemoSPList, 
                Factory = cmb_Demo1.Selected.Result
            ), 
            Library
        ),
        Result
    ),
    "Result",
    "Value"
)

 

Your DefaultSelectedItems property (not the Default) of the Combobox should be:

If(varFormMode = FormMode.New,
    RenameColumns(
        Distinct(
            Filter(
                MTDemoSPList2,
                Books = cmb_Demo1.Selected.Result
            ), 
            Library
        ),
        "Result",
        "Value"
    ),
    Parent.Default
)

 

Now, your combobox will not only have matching schemas in the defaults and the items, but it will now allow you to Update the underlying record with the .SelectedItems property of the combobox as it will also match the required record type for a Choice column. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Anonymous
Not applicable

If I use ThisItem.'Library' instead of Parent.Default, everything seems to work..

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@Anonymous 

Your formula has a mistake in it, please consider the following formula:

If(varFormMode = FormMode.New,
    Distinct(
        Filter(
            MTDemoSPList2,
            Books = cmb_Demo1.Selected.Result
        ), 
        Library
    ),
    Parent.Default
)

 

However, the bigger part will be that the Parent.Default will most likely not match your Items.  What is the underlying column type of the field you are working with?

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

Ho @RandyHayes. Thanks! The underlying column type is Choice. Why shouldn't parent.default match the Items? Is it because of the column type?

RandyHayes
Super User
Super User

@Anonymous 

Choice columns have records with a Value column.  Your formulas are all producing tables that have Result columns.  This will not match.  Comboboxes have to have matching values.

So, since you are using a combobox, your Items property should be changed to the following:

RenameColumns(
    Sort(
        Distinct(
            Filter(MTDemoSPList, 
                Factory = cmb_Demo1.Selected.Result
            ), 
            Library
        ),
        Result
    ),
    "Result",
    "Value"
)

 

Your DefaultSelectedItems property (not the Default) of the Combobox should be:

If(varFormMode = FormMode.New,
    RenameColumns(
        Distinct(
            Filter(
                MTDemoSPList2,
                Books = cmb_Demo1.Selected.Result
            ), 
            Library
        ),
        "Result",
        "Value"
    ),
    Parent.Default
)

 

Now, your combobox will not only have matching schemas in the defaults and the items, but it will now allow you to Update the underlying record with the .SelectedItems property of the combobox as it will also match the required record type for a Choice column. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

 

@RandyHayes , thank you very much for this! I updated the Items and DefaultSelectedItems as you suggested,and DefaultSelectedItems shows this error: "The function If has some invalid arguments".

the error message is gone when I remove Parent.Default from the formula and leave as this:

DefaultSelectedItems = If(varFormMode = FormMode.New,
    RenameColumns(
        Distinct(
            Filter(
                MTDemoSPList2,
                Books = cmb_Demo1.Selected.Result
            ), 
            Library
        ),
        "Result",
        "Value"
    )
)



Is it possible to fix such issue?

Anonymous
Not applicable

If I use ThisItem.'Library' instead of Parent.Default, everything seems to work..

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,489)