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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

Create a survey

(0) ShareShare
ReportReport
Posted on by 8

Hello everyone. I need to create a survey for work. At the moment we have one from google, but we need to add some new functions that google doesn't have.  Here you have a picture of what the survey looks like. 

What i need to do is to set a limit: you have to pick for options in total, but from those for options you can't pick from top to bottom more than 2 consecutive options. So for example, I want to not be able to chose more than two weekends in a row. The survey would let me chose mar 4/5 and mar 11/12 but not mar 18/19. Anyone know how can i do this?

maguimasante_0-1675968621931.png

 

Categories:
  • Verified answer
    TheRobRush Profile Picture
    11,128 Moderator on at

    Ok this will be a little complex, but I have it functional. Make a screen and set it's OnVisible to this

     

    ClearCollect(weekendTest, 
    AddColumns(
    GroupBy(
     ForAll(
     Sequence(Day(DateAdd(DateAdd(DateValue(Text(DateValue(Month(DateAdd(Now(),1,Months))&"/1/2023"), "mmmm")&" 01, "&Year(Now())),1,Months),-1,Days)),0,1) As dayStep,
     
     Switch(
     Weekday(DateAdd(DateValue(Month(DateAdd(Now(),1,Months))&" 01, "&Year(Now())), dayStep.Value, Days)),
     7,
     {DateTaken:DateAdd(DateValue(Month(DateAdd(Now(),1,Months))&" 01, "&Year(Now())), dayStep.Value, Days), WeekTaken:WeekNum(DateAdd(DateValue(Month(DateAdd(Now(),1,Months))&" 01, "&Year(Now())), dayStep.Value, Days),StartOfWeek.Monday)},
     1,
     {DateTaken:DateAdd(DateValue(Month(DateAdd(Now(),1,Months))&" 01, "&Year(Now())), dayStep.Value, Days), WeekTaken:WeekNum(DateAdd(DateValue(Month(DateAdd(Now(),1,Months))&" 01, "&Year(Now())), dayStep.Value, Days),StartOfWeek.Monday)}
     
     )
     
     ), "WeekTaken","WeekendSet"),"Choice",Value(Blank()),"QueueSpot", Value(Blank()))
     
    );
    
    
    ClearCollect(QueueCount,{Value:1});
    
    ForAll(weekendTest.WeekTaken As _item,
     UpdateIf(weekendTest, WeekTaken=_item.WeekTaken,{QueueSpot:CountRows(QueueCount)});
     Collect(QueueCount,{Value:1}));
     
    Reset(monthChoice)

     

     

    You will have some errors, ignore them, they will be resolved as we add items to the screen.

     

    Now, add a Dropdown controld name it monthChoice.

     

    Set it's Default property to

     

    Text(DateValue(Month(DateAdd(Now(),1,Months))&"/1/2023"), "mmmm")

     

     

    Set it's Items property to

     

    ForAll(Sequence(12), Text(DateValue(ThisRecord.Value&"/1/2023"), "mmmm"))

     

     

    Lastly set it's OnChange property to

     

    ClearCollect(weekendTest, 
    AddColumns(
    GroupBy(
     ForAll(
     Sequence(Day(DateAdd(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())),1,Months),-1,Days)),0,1) As dayStep,
     
     Switch(
     Weekday(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days)),
     7,
     {DateTaken:DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days), WeekTaken:WeekNum(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days),StartOfWeek.Monday)},
     1,
     {DateTaken:DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days), WeekTaken:WeekNum(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days),StartOfWeek.Monday)}
     
     )
     
     ), "WeekTaken","WeekendSet"),"Choice",Value(Blank()),"QueueSpot", Value(Blank()))
     
    );
    
    
    ClearCollect(QueueCount,{Value:1});
    
    ForAll(weekendTest.WeekTaken As _item,
     UpdateIf(weekendTest, WeekTaken=_item.WeekTaken,{QueueSpot:CountRows(QueueCount)});
     Collect(QueueCount,{Value:1}));
    

     

     

    NOW add a vertical gallery anywhere on this screen

     

    Set it's Items property to

     

    weekendTest

     

     

    Set it's TemplateSize property to

     

    Self.Height/CountRows(Self.AllItems)

     

     

    In here we will place 2 buttons, a radio control, and a label like so

    TheRobRush_0-1676047662184.png

     

     

    On our ResetChoices button make it's text read Start Over, or whatever you want and it's OnSelect Property should read

     

    ClearCollect(weekendTest, 
    AddColumns(
    GroupBy(
     ForAll(
     Sequence(Day(DateAdd(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())),1,Months),-1,Days)),0,1) As dayStep,
     
     Switch(
     Weekday(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days)),
     7,
     {DateTaken:DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days), WeekTaken:WeekNum(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days),StartOfWeek.Monday)},
     1,
     {DateTaken:DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days), WeekTaken:WeekNum(DateAdd(DateValue(monthChoice.SelectedText.Value&" 01, "&Year(Now())), dayStep.Value, Days),StartOfWeek.Monday)}
     
     )
     
     ), "WeekTaken","WeekendSet"),"Choice",Value(Blank()),"QueueSpot", Value(Blank()))
     
    );
    
    
    ClearCollect(QueueCount,{Value:1});
    
    ForAll(weekendTest.WeekTaken As _item,
     UpdateIf(weekendTest, WeekTaken=_item.WeekTaken,{QueueSpot:CountRows(QueueCount)});
     Collect(QueueCount,{Value:1}));

     

     

    and set it's Visible Property to

     

    ThisItem.QueueSpot=1

     

    so that it only appears once in the gallery.

     

    can also change that to

     

    ThisItem.QueueSpot=CountRows(weekendTest)

     

    If you prefer that appear at the bottom.

     

    Our ResetRadio button Set its Visible property to

     

    false

     

     

    and make the OnSelect property

     

    Reset(ChoiceRadio)

     

     This is necessary to keep the user from selecting the week in a restricted scenario by clicking it multiple times (the logic for restrictions fires off in the onchange, so if they don't change it (ie select a restricted answer twice in a row technically is not a change) we will still be able to restrict this choice.

     

    Now place your radio control.

     

    It's Items property should be

     

    ForAll(Sequence(CountRows(weekendTest)) As countItem, 
     Switch(countItem.Value,
     1, 
     countItem.Value&"st Choice",
     2, 
     countItem.Value&"nd Choice",
     3, 
     countItem.Value&"rd Choice",
     countItem.Value&"th Choice"))

     

     

    Make it's OnSelect property

     

    Select(ResetRadio)

     

     

    And it's OnChange property

     

    If(
     Value(Left(Self.Selected.Value,1)) in weekendTest.Choice,
     Notify("Error, Duplicate Choice Made");
     Patch(weekendTest, ThisItem, {Choice: Value(Blank())});
     Reset(ChoiceRadio); Reset(ChoiceRadio),
    
     ThisItem.QueueSpot = 1 || ThisItem.QueueSpot = 2, 
     Patch(weekendTest, ThisItem, {Choice: Value(Left(Self.Selected.Value,1))}),
     And(
     Sum(LookUp(weekendTest,QueueSpot=ThisItem.QueueSpot-1).Choice-LookUp(weekendTest,QueueSpot=ThisItem.QueueSpot-2).Choice)=1, 
     Value(Left(Self.Selected.Value,1))=Value(LookUp(weekendTest,QueueSpot=ThisItem.QueueSpot-1).Choice)+1
     ),
     Notify("Error, Weekends Can Only be Ranked Consecutively Twice.");
     Patch(weekendTest, ThisItem, {Choice: Value(Blank())});
     Reset(ChoiceRadio); Reset(ChoiceRadio),
    
     Patch(weekendTest, ThisItem, {Choice: Value(Left(Self.Selected.Value,1))}));
    
    
     Reset(Self) 
    

     

     

    Its Default property is

     

     Switch(Value(ThisItem.Choice),
     1, 
     ThisItem.Choice&"st Choice",
     2, 
     ThisItem.Choice&"nd Choice",
     3, 
     ThisItem.Choice&"rd Choice",
     4,
     ThisItem.Choice&"th Choice",
     5,
     ThisItem.Choice&"th Choice",
     Blank())

     

     

    And then for the label I just put this for it's Text property

     

    Text(First(ThisItem.WeekendSet).DateTaken, "mmm d/")&Text(Last(ThisItem.WeekendSet).DateTaken, "d")

     

     

    All this gives you the survey and has it start off having user rank all the weekend dates for the NEXT month. Only let's you rank consecutively 2x (and gives a warning message if you try to do 3)  Only lets you pick a ranking once (warning if you try to rank two things first for example) has a button if user messes it up too much to reset and start over, and also has a month selector that you can use to rank months that aren't the next month if you want. can hide that if not.

     

    Here's what pops up (see top of image) when I try to select first weekend as first choice, second weekend as second choice, then ATTEMPT to click third choice for 3rd weekend

    TheRobRush_1-1676048467657.png

     

     

    And here is what happens when I try and select first choice for week 3 when it is already a rankign I gave to the first week.

    TheRobRush_2-1676048556545.png

     

     

    I think this is just about the easiest way you can accomplish this, it's a fairly complex set of conditions I think, unless I am over complicating it in my mind. @timl you wouldn't happen to see anything I could have made easier do you?

  • maguimasante Profile Picture
    8 on at

    Thank you so much! I really appreciate

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Anytime, Be sure to accept a solution once it is up and working, so other looking for similar problems can more easily find the answer!

  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    Hi @TheRobRush 

    Thanks for tagging me, and for posting such a great solution to a challenging problem!

    I can't think of an easier solution. I toyed with the idea of maybe assigning some unique value or identifier to each radio option, and creating a whitelist/blacklist of acceptable values. Ultimately, I think this would have just as, or more complex.

  • maguimasante Profile Picture
    8 on at

    Hi everyone! 

     

    Hope you are doing well. I really appreciate your help in this. It's my first time using PowerApps and i'm trying to understand how everything works. I was thinking, do you think it could be easier if: 

    1) I create the screen 1: there I would have the 1st choice, 2nd choice, 3rd and 4th choice in a dropdown with the dates for the time period. 

    2) after they respond to this, there could be a screen 2. My idea is that maybe there, all of the responses and choices would appear. We could add a "submit survey" button, where if you chose 3 consecutive weekends, it doesn't let you submit it. 

     

    Does this make sense? Do you think this could be easier?

  • TheRobRush Profile Picture
    11,128 Moderator on at

    What I have provided already will not let you select 3 in a row. Just follow those instructions I provided. Checking after would be the same level as complexity, but then make you have to go back and forth as a user to fix it so is not a good choice.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 350 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 318

#3
Mohsin Ali Profile Picture

Mohsin Ali 220

Last 30 days Overall leaderboard