web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Power Apps set a dropdown value based on variable

(0) ShareShare
ReportReport
Posted on by 67

Hi Members,

 

I have a requirement in Power Apps where I want to set a dropdown value based on a variable.

 

Scenario:

I have two SharePoint lists Company details and Employee Details. The company details list includes all departments. The employee details list will save all details of the employees with their department.

 

In Power Apps, there are Text input control, a search icon, and a Dropdown control.

 

If the user enters the Employee ID in the text input control and clicks on the search icon. 

 

The employee ID will be fetched from the Employee details SharePoint list and displayed in their department in the dropdown control.

 

In the Search icon button, I have set a variable as 

Set(varEmp,TextInput1)

Variable Error.jpg

 

Then in the Power Apps dropdown control, Items property, I have put the below code:

)
If(
 IsBlank(varEmp),
 Distinct(
 'Company Details',
 Name
 ),
 (LookUp(
 'Employee Details',
 TextInput1 = varEmp
 ).Department)
)

Variable Error2.jpg

 

But, I was facing an issue like, the dropdown control value was fetching only SharePoint list 1st value as IT. 

 

For example, If I give the Employee ID = TS763 and click on the search icon the dropdown value will be fetched as IT only.

Variable Error3.jpg

But the Employee ID TS763, is belongs to the marketing department.

Variable Error4.jpg

I need the dropdown item should be selected based on the Employee ID.

 

Can anyone please suggest how I can resolve this? Thanks in advance!

I have the same question (0)
  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at
    Re: Power Apps set a dropdown value based on variable

    You want the Items list to be the full list of Departments and the Default value for display is the ThisItem property. That way you will have the correct display, but be able to select others.

  • Hema123 Profile Picture
    7 on at
    Re: Power Apps set a dropdown value based on variable

    No, I need my dropdown value should be selected based on the Employee ID.

     

    I need to set the variable in the search button.

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at
    Re: Power Apps set a dropdown value based on variable

    If you are returning only the single value for the Employee, why are you using a Drop-down control? If you only want one value a label will be all you need. It looks like your code returns a table for the True Value and a single test item for the False Value. Also your Lookup is probably returning the first record because your formula is true. Don't you want the Lookup to be Lookup('Employee Details', varEmp=EmployeeID).Department?

     

  • Hema123 Profile Picture
    7 on at
    Re: Power Apps set a dropdown value based on variable

    Hi @BrianS Thanks for your reply. I think nearly there. Still getting below warning. How do we solve this please?

    Error 5.jpg

    And the dropdown control doesn't show me any value

    Error 6.jpg

  • NPPlatform Profile Picture
    606 Moderator on at
    Re: Power Apps set a dropdown value based on variable

    @Hema123 The warning tells you that you are trying to compare a boolean (yes/no-field) with a text-field. Apparently varEmp can only be yes or no. If you want to use it in your lookup to compare with an ID, you'll have to change your variable to contain the ID. 

     

    ___________________________

     

    If this solved your problem, please consider marking it as the solution. 

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at
    Re: Power Apps set a dropdown value based on variable

    You may be using varEmp in another part of your app. There is a search function now on the left hand pane. You can search for all occurrences of the variable and fix one if it's a Boolean

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 624 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 381 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 225

Last 30 days Overall leaderboard