cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JamFestival
Helper I
Helper 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
Helper I
Helper I

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

Please share Dropdown1Q22 - Items property. 

JamFestival
Helper I
Helper 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
Helper I
Helper 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
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

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