cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ElMigol
New Member

Adding 1 to a variable doesn't work

So basically I have a quiz with 38 questions, every question is in different pages so I have 1 welcome page, 38 question pages, 1 to save colors and to play the timer (user never access this) and 1 last page that tells the user their score.

 

The way the apps calculates the score is with a variable called 'Score', when the correct answer is selected (in a Radio input) and then the user clicks the 'Next' button, this button adds 1 to the variable, if the user doesn't select the correct answer it doesn't add nothing and just navigates to the next question:

 

 

 

If(
    Answers_2.Selected.Value = "The Product Owner.",
    Set(
        Score,
        Score + 1
    )
);
Navigate(Question_3)

 

 

 

My problem is that this works only in the first 6 questions, when you try to answer the question in question 7 to question 38 it doesn't add anything, even if you select the correct answer and I don't know why. I've been trying to figure this out for like 5 hours but I just don't understand why it doesn't work.

1 ACCEPTED SOLUTION

Accepted Solutions
v-yujincui-msft
Community Support
Community Support

Hi @ElMigol ,

 

Based on your description, it seems there is no problem with the text value used for comparison. To be honest, I can't find the reason why your formula doesn't work at the moment.

 

In addition, I have an idea for tallying scores, but it may take you some time, so try it if you're interested.

1. When the correct answer is selected and then the user clicks the 'Next' button, this button will add a record to the collection.

2. The last record in the collection will be deleted if the user needs to navigate to the previous question.

3. Use the CountRows() function on the last screen to count the scores.

If(
    Answers_1.Selected.Value = "A",
    Collect(AnswersCollection,{page:"Q1",result:"true"})
);
Navigate(Question_2)
RemoveIf(AnswersCollection,page="Q1");Navigate(Question_1)
"Score: "&CountRows(AnswersCollection)

vyujincuimsft_0-1651740699003.png

vyujincuimsft_1-1651740797129.png

vyujincuimsft_2-1651740859251.png

vyujincuimsft_3-1651740916445.png

Hope it can be helpful to you.

 

 

Best Regards,

Charlie Choi

View solution in original post

8 REPLIES 8
RandyHayes
Super User
Super User

@ElMigol 

There is no reason it would not work on other screens.  However, what is significant in your formula is that you are comparing text.  In that case, the text MUST be an exact match (letter case, punctuation, etc.).  So, if there is any difference, your score variable will not get updated.

 

You might consider being a little more loose with the formula.

Ex:

If(
    StartsWith(Answers_2.Selected.Value, "The Product Owner"),
    Set(
        Score,
        Score + 1
    )
);
Navigate(Question_3)

The above would ignore letter case and the punctuation is omitted.

 

If this is not helpful, then post the formula from your screen that is not working.  The one you posted implies that it is on what would potentially be question number 3...you stated that question 6 and on have issues.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Nogueira1306
Super User
Super User

The only think that I am thinking of is "about the self reference".. In Power automate you can not do that for example.

 

What you can try:

 

If(
    Answers_2.Selected.Value = "The Product Owner.",
    Set(QuestionScored, Score);
    Set(
        Score,
        QuestionScored + 1
    )
);
Navigate(Question_3)

 

So, you create a new var to save the "new" score and after that add 1 to get the global

 

If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!

Best regards,

Gonçalo Nogueira

Check my LinkedIn!

Buy me a coffee!

Check my User Group (pt-PT)!

Last Post on Community

My website!

Thank you for you reply! I'm pretty sure that the text comparison is fine since every text line is copied and pasted from a Microsoft Form that my boss sent to me. Either way I tried replacing my code with yours but still it doesn't work. So this is my code for the button on question 7:

If(
   Answers_7.Selected.Value="15 minutes",
    Set(
        Score,
        Score + 1
    )
);
Navigate(Question_8)

 As you can see it's literally the same for every single button, that's why I can figure out why it doesn't work.

Thank you for your reply!

If this was Power Automate it would make sense but I'm working on Power Apps. Even if that was the case, this doesn't work only from question 7 to question 38, from question 1 to question 6 it works perfectly fine. Either way I tried you code but it still doesn't work.

@ElMigol 

Yes, so again, the formula is syntactically correct, so the comparison is not seeming to happen.

Once you get to the point of clicking on that next button, instead look in your formula and highlight the Answers_7.Selected.Value part of the formula and see what the formula editor is telling you that the value is.  Compare that to what you are comparing to in the text in the formula...is it the same?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
ElMigol
New Member

Yes, it is the same.

v-yujincui-msft
Community Support
Community Support

Hi @ElMigol ,

 

Based on your description, it seems there is no problem with the text value used for comparison. To be honest, I can't find the reason why your formula doesn't work at the moment.

 

In addition, I have an idea for tallying scores, but it may take you some time, so try it if you're interested.

1. When the correct answer is selected and then the user clicks the 'Next' button, this button will add a record to the collection.

2. The last record in the collection will be deleted if the user needs to navigate to the previous question.

3. Use the CountRows() function on the last screen to count the scores.

If(
    Answers_1.Selected.Value = "A",
    Collect(AnswersCollection,{page:"Q1",result:"true"})
);
Navigate(Question_2)
RemoveIf(AnswersCollection,page="Q1");Navigate(Question_1)
"Score: "&CountRows(AnswersCollection)

vyujincuimsft_0-1651740699003.png

vyujincuimsft_1-1651740797129.png

vyujincuimsft_2-1651740859251.png

vyujincuimsft_3-1651740916445.png

Hope it can be helpful to you.

 

 

Best Regards,

Charlie Choi

LukeShive
Frequent Visitor

It looks to me that Your condition is either not meet or you are referring to the wrong Radio control ... You are sure that all that is right ?

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,098)