cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
emfuentes27
Advocate II
Advocate II

Loop collection and get the value of field B if field A meet condition

I created a collection that contains the States, and its abbreviation:

 

 

ClearCollect(
    theStates,
    Table(
        {
            State: "Alabama",
            Abbr: "AL",
            Capital: "Montgomery"
        },
        {
            State: "Alaska",
            Abbr: "AK",
            Capital: "Juneau"
        },
        {
            State: "Arizona",
            Abbr: "AZ",
            Capital: "Phoenix"
        },......

 

When our users open the page I get the OfficeLocation by running Set(myStateAbbr, Left(Office365Users.MyProfile().OfficeLocation), 2). Due to the way our profiles are configures myStateAbbr will always return the State abbreviation without fail. What I would need to do is to loop through theStates collection, and if Abbr matches myStateAbbr, then get the State name. For example:

 

I'm located in Colorado. When I open the page, my myStateAbbr is CO. Then I need to loop my collection, and get what State corresponds to that abbreviation, which will return "Colorado".

 

Thanks in advance.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
BCLS776
Community Champion
Community Champion

I believe you are after another Lookup() here, not a loop:

 

Lookup(theStates, Abbr = myStateAbbr, State)

This lookup should return the string "Colorado" for you

View solution in original post

iltoningui
New Member

Hi @emfuentes27 

 

This should help you

Set(myStateAbbr, "AK");
ClearCollect(
    theStates,
    Table(
        {
            State: "Alabama",
            Abbr: "AL",
            Capital: "Montgomery"
        },
        {
            State: "Alaska",
            Abbr: "AK",
            Capital: "Juneau"
        },
        {
            State: "Arizona",
            Abbr: "AZ",
            Capital: "Phoenix"
        }
    )
);
Set(myState, LookUp(theStates, Abbr = myStateAbbr).State)

 

If this is the answer you were looking for consider marking this as a solution. 

View solution in original post

2 REPLIES 2
BCLS776
Community Champion
Community Champion

I believe you are after another Lookup() here, not a loop:

 

Lookup(theStates, Abbr = myStateAbbr, State)

This lookup should return the string "Colorado" for you

View solution in original post

iltoningui
New Member

Hi @emfuentes27 

 

This should help you

Set(myStateAbbr, "AK");
ClearCollect(
    theStates,
    Table(
        {
            State: "Alabama",
            Abbr: "AL",
            Capital: "Montgomery"
        },
        {
            State: "Alaska",
            Abbr: "AK",
            Capital: "Juneau"
        },
        {
            State: "Arizona",
            Abbr: "AZ",
            Capital: "Phoenix"
        }
    )
);
Set(myState, LookUp(theStates, Abbr = myStateAbbr).State)

 

If this is the answer you were looking for consider marking this as a solution. 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,121)