# Quiz Subscores

Moodle users sometimes ask how to extract subscores or subtotals from Quiz. For examples, see Multiple grade quizzes and Quiz with sub-totaled sections?

Here is a method to extract subscores from Quiz (or any other Moodle activity that allows you to set different point values per question), without requiring any changes to Moodle code. It is a bit complex, but it does work. However, this method is only useful if you don't plan to use or display the final Quiz score, but you only want to display and use the subscores.

This method is based on the modulo operation and Floor function (Definitions of functions).

## Step 1: Create Quiz and set values of Questions

Start by creating a quiz as usual. However, for each subscore you want to extract, you will need to set the values of questions for that subscore to an order of magnitude matching that subscore. This is easiest to understand with an example. Suppose you are creating a test that will contain questions from three areas: Mathematics, Language, and History. In this example, Mathematics is Topic 1, Language is Topic 2, and History is Topic 3.

For each topic, use a different point value for each question in that topic. For Topic 1 (Mathematics), each question is worth 1 point. For Topic 2 (Language), each question is worth 10 points. For Topic 3 (History), each question is worth 100 points. (Note that this is going to make your final quiz score meaningless.)

**Important**: set the total points of the quiz to the same as the total of all the questions. Otherwise, the Quiz will change its scores based on whatever you set as the maximum number of points for the Quiz, and your calculations in later steps won't work correctly.

You also need to give the Quiz activity an ID number that you will be able to remember later. In this example we will use "Pretest".

## Step 2: Create Grade Items for each topic

Next, create one new Manual Grade Item for each of your Topics. **Important**: put these Grade Items into a separate category that does NOT have Natural Weighting as the grade aggregation method. After saving each Grade Item, you will edit the Calculation for the item directly in the item's Edit menu.

The calculation looks like this (where [[Pretest]] is the ID of the quiz score you are breaking into subscores):

=mod(floor([[Pretest]]/topicvalue),10)

where "topicvalue" is the same as the number of points each question in the topic is worth in step 1. So for Topic 1, the calculation is:

=mod(floor([[Pretest]]),10)

For Topic 2, the calculation is:

=mod(floor([[Pretest]]/10),10)

For Topic 3, the calculation is:

=mod(floor([[Pretest]]/100),10)

Definitions of functions available in Gradebook Calculations:

mod(dividend, divisor): Calculates the remainder of a division

floor(number): Maps a real number to the largest previous integer

What this does is extract the digit from the quiz grade. So Topic 1 gets the "ones" digit, topic 2 gets the "tens" digit, etc. Note that this means you can only have up to 10 topic areas, and up to 10 quiz questions per topic. It is possible to use this method for larger numbers of topics or questions per topic, but you will need to adjust the math accordingly (e.g. you could use hexidecimal values and have up to 16 topics and 16 questions per topic).

At this point, you may want to test your quiz with some sample students so you can see how this looks in the Gradebook.

**Note**: you can aggregate these subscores at the level of the category you created for them by using any of the available aggregation methods (sum, mean, min, max, etc.) and show the result in place of the original Quiz score, if needed.

## Use your Subscores

Now, you have manual grade items for each topic, and they have values you can use in controlling visibility/access to activities. For example, set some labels to display or not display based on subscores from the first quiz. These labels can contain advisory text to students, letting them know whether they should complete a section of the course. You could also hide the section if the student has done well enough on the pretest, or show a section that is normally hidden if the student did poorly enough to need remedial material.