cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JamFestival
Resolver I
Resolver I

Dropdown - reference whether a selected choice item is first, second, third etc., as opposed to its text in an If statement

Hi,
I have a lengthy self-assessment set up in a PowerApp, populating a Sharepoint list
Many of the questions are 'Choice' columns in the SharePoint list, and I am using forms with drop-down datacards in PowerApps.
Currently, I am using ...Selected.Value in If statements to assign a score for that question to a Context Variable that adds to a total global variable.

The flaw with this approach is if I don't have the EXACT text as defined in the SharePoint list's choice column in quotes, it isn't going to assign a score, leaving much margin for error. In addition, I am likely to have to edit the responses after user feedback, and this is going to generate a lot of extra work.

 

Is there a way of referencing, in, for example, a four-option choice as a drop-down, whether it is the first, second, third, and fourth value, irrespective of its actual value?

 

So instead of:
If(Dropdown1Q22.Selected.Value = "I wait until someone shows me how to use it",UpdateContext({ScreenScore:1}));
If(Dropdown1Q22.Selected.Value = "I commit time to getting familiar with it",UpdateContext({ScreenScore:2}));
If(Dropdown1Q22.Selected.Value = "I am confident enough to use the software and look for online help if needed",UpdateContext({ScreenScore:3}));
If(Dropdown1Q22.Selected.Value = "When software is updated, I will start by looking at and evaluating new features",UpdateContext({ScreenScore:4}));

 

I could have something along the lines of:
If(Dropdown1Q22.Selected= 1,UpdateContext({ScreenScore:1}));
If(Dropdown1Q22.Selected= 2,UpdateContext({ScreenScore:2}));
If(Dropdown1Q22.Selected= 3,UpdateContext({ScreenScore:3}));
If(Dropdown1Q22.Selected= 4,UpdateContext({ScreenScore:4}));

 

...so the If statement is more robust?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @JamFestival :

Please try:

Clear(TheCount);
ForAll(
   Choices ([@POC].'When I need to use new software, or software I use is updated: '),
   If(
       Dropdown1Q22.Selected.Value=Value,
       Collect(TheCount,{Value:1},{Value:0}),
       IsBlank(LookUp(TheCount,Value=0)),
       Collect(TheCount,{Value:1}),
       Collect(TheCount,{Value:0})));
UpdateContext({ScreenScore:Sum(TheCount,Value)})

I've made a test for your reference:

8.gif

 Best Regards,

Bof

View solution in original post

6 REPLIES 6
gabibalaban
Dual Super User
Dual Super User

@JamFestival ,

Please check this approach:

Switch(
     Dropdown1Q22.Selected.Id,
     1,
     UpdateContext({ScreenScore:1}),
     2,
     UpdateContext({ScreenScore:2}),
     3,
     UpdateContext({ScreenScore:3}),
     4, 
     UpdateContext({ScreenScore:4})
)

Hope it helps !

JamFestival
Resolver I
Resolver I

Thanks.
Unfortunately, it doesn't recognise the '.Id' part.

Please share Dropdown1Q22 - Items property. 

JamFestival
Resolver I
Resolver I

It is:
Choices ([@POC].'When I need to use new software, or software I use is updated: ')

 

POC is the name of the sharepoint list

Hi @JamFestival :

Please try:

Clear(TheCount);
ForAll(
   Choices ([@POC].'When I need to use new software, or software I use is updated: '),
   If(
       Dropdown1Q22.Selected.Value=Value,
       Collect(TheCount,{Value:1},{Value:0}),
       IsBlank(LookUp(TheCount,Value=0)),
       Collect(TheCount,{Value:1}),
       Collect(TheCount,{Value:0})));
UpdateContext({ScreenScore:Sum(TheCount,Value)})

I've made a test for your reference:

8.gif

 Best Regards,

Bof

JamFestival
Resolver I
Resolver I

Thank you so much for this advice. I haven't had the opportunity to try it until now, so sorry for the delay in responding. It works flawlessly!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,432)