I've reused a PowerApps example of a questionnaire and moderated tsome of the questions. This solution has this formula on the next button of the last question to insert all answers from the user in the Responseds tab on the data Excel. I can see its goal (check if there is already an entry for that user and if so, update existing record otherwise insert the record).
If(!IsBlank(LookUp(Responses;Username=User().FullName;Responses));UpdateIf(Responses;Username=User().FullName;{ResponseId:ResponseId; Answer1:Radio1.SelectedText.OptionText;Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");Answer3:Text(Slider1.Value); Answer4:Radio1_1.SelectedText.OptionText;Answer5:Radio5_1.SelectedText.OptionText;Username:User().FullName});
UpdateContext({NewSurvey:Patch(Responses;Defaults(Responses); {ResponseId:Text(CountRows(Responses)+1); Answer1:Radio1.SelectedText.OptionText;Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");Answer3:Text(Slider1.Value); Answer4:Radio1_1.SelectedText.OptionText;Answer5:Radio5_1.SelectedText.OptionText;Username:User().FullName})}));;Navigate(Finish_Screen;ScreenTransition.Fade)
I can enter the answers in the quiz without errors. However when the datasheet Responses is empty or it does not have a previous record for that user, it does not insert the anwsers. IF there is already an answer for that user, it updates it.
When I only use this part, it inserts every entry:
UpdateContext({NewSurvey:Patch(Responses;Defaults(Responses); {ResponseId:Text(CountRows(Responses)+1); Answer1:Radio1.SelectedText.OptionText;Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");Answer3:Text(Slider1.Value); Answer4:Radio1_1.SelectedText.OptionText;Answer5:Radio5_1.SelectedText.OptionText;Username:User().FullName})});;Navigate(Finish_Screen;ScreenTransition.Fade)
Can anyone help me what I need to change to the first formula so it works correctly. Update when records exists, insert when there ar no records or no record for that user.
Solved! Go to Solution.
Can you try to update the formula as:
If(
CountRows(Filter(Responses;Username=User().FullName))>0;
UpdateIf(Responses;Username=User().FullName;
{
ResponseId:ResponseId;
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName});
UpdateContext(
{NewSurvey:
Patch(Responses;Defaults(Responses); {
ResponseId:Text(CountRows(Responses)+1);
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName})}));;Navigate(Finish_Screen;ScreenTransition.Fade)
Hope this Helps!
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Hi @SueZeeBee_ganto ,
I have made a test on my side, please consider modify your formula as below:
If(
!IsBlank(LookUp(Responses; Username = User().FullName)); // Mofify formula here
UpdateIf(
Responses;
Username=User().FullName;
{
ResponseId: ResponseId;
Answer1:Radio1.SelectedText.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.SelectedText.OptionText;
Answer5:Radio5_1.SelectedText.OptionText;
Username:User().FullName
}
);
UpdateContext({
NewSurvey: Patch(
Responses;
Defaults(Responses);
{
ResponseId: Text(CountRows(Responses)+1);
Answer1:Radio1.SelectedText.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.SelectedText.OptionText;
Answer5:Radio5_1.SelectedText.OptionText;
Username:User().FullName
}
)
})
);;
Navigate(Finish_Screen;ScreenTransition.Fade)
or
Set(FindingRecord, LookUp(Responses; Username = User().FullName));;
If(
!IsBlank(FindingRecord); // Mofify formula here
UpdateIf(
Responses;
Username=User().FullName;
{
ResponseId: ResponseId;
Answer1:Radio1.SelectedText.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.SelectedText.OptionText;
Answer5:Radio5_1.SelectedText.OptionText;
Username:User().FullName
}
);
UpdateContext({
NewSurvey: Patch(
Responses;
Defaults(Responses);
{
ResponseId: Text(CountRows(Responses)+1);
Answer1:Radio1.SelectedText.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.SelectedText.OptionText;
Answer5:Radio5_1.SelectedText.OptionText;
Username:User().FullName
}
)
})
);;
Navigate(Finish_Screen;ScreenTransition.Fade)
Please consider take a try with above solution, then check if the issue is solved.
Best regards,
Thank you for your reaction. I've replaced my formula with both versions of the formulas on a blank Excel datasheet. In both cases this leads to insert with a new record but without data from the questionnaire. Only the powerapps_id column shows data.
Can you try to update the formula as:
If(
CountRows(Filter(Responses;Username=User().FullName))>0;
UpdateIf(Responses;Username=User().FullName;
{
ResponseId:ResponseId;
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName});
UpdateContext(
{NewSurvey:
Patch(Responses;Defaults(Responses); {
ResponseId:Text(CountRows(Responses)+1);
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value);
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName})}));;Navigate(Finish_Screen;ScreenTransition.Fade)
Hope this Helps!
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
That did the trick, thank you!
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
260 | |
128 | |
86 | |
85 | |
68 |