cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lephas
Helper I
Helper I

Default Selected Items based on different List with possible multiple Values

Hi guys

I tried a couple of things how to solve this but I am a little bit stuck.

I have 2 Lists:

1) Input Form List: Two columns Country(A) and Regions(A). Both are Coice fields but Region can have multiple Regions selected.

2) Region Mapping List: Two columns, Countries(B) and Region(B) as well. Both Choice fields but Countries can have multiple Items selected.

 

Country(A) is a the country field of the currently logged in User

The Region is a Mapping list to associate Regions with countries.

For example

Region: EU

Countries: Germany, England, Denmark etc.

Region: NA

Countries: USA, Canada, Mexico

Region: America:

Countries: USA, Canada, Mexico, Brazil, Peru etc.

 

For Regions(A) I want to have selected by Default the Region(s) from the Region Mapping List(2) which contains the same Countries(B) like the currently signed in User Country (A)
So for example if i am from Germany, EU will be selected as a Region

If i am from Mexico i will have 2 Regeions selected: NA and America

 

So currently i think my best approach is the following but it's not working:

DefaultSelectedItem Property of Regions(A)

 

If(
    'FormA'.Mode=FormMode.New;
    {
		Value: Filter(
        ('Region Mapping');Country_DataCardValue.Selected.Value in Countries.Value
        ).Region 
        //Countries(B) is the Field from the Region Mapping List
        // Country_DatacardValue.Selected.Value is Country(AI
	};
    Parent.Default
)

 

 

Am i any close or do i have to apporach this differently?

Any help is highely appreciated!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Lephas 

You are on the right road!

The only part that will be important is to make sure the the records table in the DefaultSelectedItems property has the exact same schema as the Items property of the combobox.  As long as they do and as long as the values are in the Items table, then you will have selected items.

 

Now, for your formula, you need to have a table, not just a single record.  So your formula should be:

Coalesce(
    ForAll(
        Filter(
            'Region Mapping'; Country_DataCardValue.Selected.Value in Countries.Value
        );
        {
            Value: Region 
        }
    );
    Parent.Default
)

 

This will give you a table of records with a Value column that contains the region based on the filter.

 

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.
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

3 REPLIES 3
RandyHayes
Super User
Super User

@Lephas 

You are on the right road!

The only part that will be important is to make sure the the records table in the DefaultSelectedItems property has the exact same schema as the Items property of the combobox.  As long as they do and as long as the values are in the Items table, then you will have selected items.

 

Now, for your formula, you need to have a table, not just a single record.  So your formula should be:

Coalesce(
    ForAll(
        Filter(
            'Region Mapping'; Country_DataCardValue.Selected.Value in Countries.Value
        );
        {
            Value: Region 
        }
    );
    Parent.Default
)

 

This will give you a table of records with a Value column that contains the region based on the filter.

 

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.
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

Lephas
Helper I
Helper I

Thank you so much! i never heard of this function but after reading into it - it makes a little bit more sense and it works just like i wanted.
I have a follow up question though: The formula works great but i get a warning about delegation and that it might not work for bigger Datasets - is this because of the In function?

 

RandyHayes
Super User
Super User

@Lephas 

Yes, the In operator is not delegable to the datasource and you will get this warning.

If your 'Region Mapping' datasource has more than 2000 records, then the In operator will be an issue.

If it is less than 2000 (and more significantly less than your record limit set in your app) then you can ignore the warning.

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,139)