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 Platform Community / Forums / Power Apps / How to make scoring
Power Apps
Suggested Answer

How to make scoring

(0) ShareShare
ReportReport
Posted on by 74
Hi, 
 
May I request for assistant on how to make a scoring in my quiz application. 
 
This is my code in my quiz application. 
 
/*Stored answer value*/
 
ForAll(
    GCGIntranetQuizGal.AllItems,
    Collect(
        colRadio,
        {
            Radio: ThisRecord.Radio4.Selected.Value,
            Questionss: ThisRecord.QuestionNumber
        }
    )
);
 
/*Set the right answer*/
 
ClearCollect(
    colCorrectAnswers,
    {
        Question: 1,
        CorrectAnswer: "EIMS"
    },
    {
        Question: 2,
        CorrectAnswer: "MRRS"
    },
    {
        Question: 3,
        CorrectAnswer: "DIRECTORY"
    }
);
 
/*Verify the if the answer of user is equal to right answer.*/
 
ClearCollect(
    colResults,
    ForAll(
        colRadio,
        {
            Question: Questionss,
            UserAnswer: Radio,
            CorrectAnswer: LookUp(
                colCorrectAnswers,
                Questionss = ThisRecord.Question
            ).CorrectAnswer,
            IsCorrect: If(
                Radio = LookUp(
                    colCorrectAnswers,
                    Questionss = ThisRecord.Question
                ).CorrectAnswer,
                true,
                false
            )
        }
    )
);
 
Thank you

 
I have the same question (0)
  • Niranjanbabu Chakali Profile Picture
    23 on at

    Hello,

    Please refer to the code below for scoring.

    I have highlighted my added code in bold.


    /* Store the user's answers */
    ForAll(
        GCGIntranetQuizGal.AllItems,
        Collect(
            colRadio,
            {
                Radio: ThisRecord.Radio4.Selected.Value,
                Questionss: ThisRecord.QuestionNumber
            }
        )
    );
    /* Set the correct answers */
    ClearCollect(
        colCorrectAnswers,
        { Question: 1, CorrectAnswer: "EIMS" },
        { Question: 2, CorrectAnswer: "MRRS" },
        { Question: 3, CorrectAnswer: "DIRECTORY" }
    );
    /* Verify if the user's answer is correct and calculate score */
    Clear(colResults); // Clear previous results
    Set(varScore, 0);  // Initialize score
    ForAll(
        colRadio,
        Collect(
            colResults,
            {
                Question: Questionss,
                UserAnswer: Radio,
                CorrectAnswer: LookUp(colCorrectAnswers, Question = Questionss).CorrectAnswer,
                IsCorrect: If(
                    Radio = LookUp(colCorrectAnswers, Question = Questionss).CorrectAnswer,
                    true,
                    false
                )
            }
        );
        
        /* Update the score */
        If(
            Radio = LookUp(colCorrectAnswers, Question = Questionss).CorrectAnswer,
            Set(varScore, varScore + 1)  // Increment score if correct
        )

    );
    /* Display the total score */
    Set(varFinalScore, varScore);  // Store the final score for display
  • Suggested answer
    Nandit Profile Picture
    1,568 Moderator on at
    Hi 
     
    I have updated your colResults code to include a Score column, 1 if the answer is correct otherwise 0. At end we can do a Sum of the column to get the final score. 
    ClearCollect(
        colResults,
        ForAll(
            colRadio,
            {
                Question: Questionss,
                UserAnswer: Radio,
                CorrectAnswer: LookUp(
                    colCorrectAnswers,
                    Questionss = ThisRecord.Question
                ).CorrectAnswer,
                IsCorrect: If(
                    Radio = LookUp(
                        colCorrectAnswers,
                        Questionss = ThisRecord.Question
                    ).CorrectAnswer,
                    true,
                    false
                ),
    Score: If(
                    Radio = LookUp(
                        colCorrectAnswers,
                        Questionss = ThisRecord.Question
                    ).CorrectAnswer,
                    1,
                    0
                )
            }
        )
    );
    
    Set(varFinalScore, Sum(colResults, Score));
     
    Hi Niranjanbabu Chakali - Your approach will work but I think you will need to wrap your "Update the score" code in a ForAll(colRadio to make it work for all questions. 
     
    ForAll(colRadio, 
     If(
            Radio = LookUp(colCorrectAnswers, Question = Questionss).CorrectAnswer,
            Set(varScore, varScore + 1), // Increment score if correct
            false  
        ))
     
    Hope this helps. 
     
    Kind regards, 
    Nandit
     
    If this answers your query, please mark this response as the answer.
    If its helpful, please leave a like. Thanks!

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 477

#2
WarrenBelz Profile Picture

WarrenBelz 341 Most Valuable Professional

#3
11manish Profile Picture

11manish 317

Last 30 days Overall leaderboard