# Step 8 - Grade Level Sorting

> Tutorial 2 for Pro Version: Using Report Bands

## Step 8 - Grade Level Sorting (\*If Necessary)

The grade levels in your chart may be sorted incorrectly.

For example, you may notice that Grades "10, "11", or "12" are not in the right order. Or, you may notice that Grades "K", "TK", "PreK", etc. are showing last.

This is happening because the Grade Level field is a "String" (aka "text") field, and the chart is sorting the grade levels alphabetically.

There are two scenarios, which will call for different solutions:

### Scenarios

1. Your data includes ***only numeric grade levels*** (i.e. Grades 1-12, but NOT Grades K, TK, etc.)
2. Your data includes ***non-numeric grade levels*** (i.e. Grades K, TK, etc.) &#x20;

## Scenario 1  - Numeric Grade Levels Only

If your dataset includes only numeric grade levels, you can simply tell Jaspersoft to treat your `Grade Level` field as if it were an Integer, and it will sort your grade levels correctly.

* Navigate to your **Outline** tab
* Select the `Current Grade Level` field under the "Fields" section in your outline.
* Go to the **Properties** tab
* Change the **Class** to `java.lang.Integer`

Preview your report. Your grade levels should now be sorting correctly.

**WARNING**: If, *at any point*, the dataset includes a grade level that is not numeric, the report will throw an error and will not run.

Only use this method if you are absolutely sure the dataset for this report will *never* include non-numeric grade levels.

## Scenario 2 - Data Contains Non-numeric Grade Levels

If your dataset includes non-numeric grade levels, you'll need to create a variable that transforms your grade levels into pure numeric values.

#### Create "Grade Level Numeric" Variable

* Navigate to your **Outline** tab
* **Right-click** on the **Variables** section in your outline
* Select **Create Variable**

![](https://950445536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4GLkzIBhRPJYBUJD8p%2F-M4GLmpngX5uSfgbRicS%2F-M4GLzSwp5nDlsvxk1f3%2FTutorial_2_Pro_Version_Create_VariableResize.jpg?generation=1586207935219439\&alt=media)

* Select the newly created **Variable\_1** variable in the outline
* **Rename** the variable to: "Grade Level Numeric" &#x20;
* Set the **Value Class Name** to `java.lang.Integer`
* Click the **pencil icon** to the right of the expression field to bring up the expression editor.

![](https://950445536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4GLkzIBhRPJYBUJD8p%2F-M4GLmpngX5uSfgbRicS%2F-M4GLzSyeOcPxlEPmEG3%2FTutorial_2_Pro_Version_Rename_Grade_Level_Sort_VariableResize.jpg?generation=1586207935459423\&alt=media)

#### Translate Grade Levels to Numeric Values

**TIP:** ***Know your data!*** To use the BI Tool effectively, you need to know your data. Look at the data in your custom report. Grade Levels are unique to *your* instance of Illuminate. Do you have "Pre-K"? "TK"? etc. *You may need to adjust the expression below to account for the grade levels you have in your Illuminate site.*

In the expression editor,

* Write the following Expression:&#x20;
  * You may need to customize the expression to account for the unique grade levels that you have in your  Illuminate site.  &#x20;

```
$F{Current Grade Level}.equals("TK")
    ? -1
:$F{Current Grade Level}.equals("K")
    ? 0
:INTEGER_VALUE($F{Current Grade Level})
```

![](https://950445536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4GLkzIBhRPJYBUJD8p%2F-M4GLmpngX5uSfgbRicS%2F-M4GLzT-cHGgl2TEXkUr%2FTutorial_2_Pro_Version_Expression_for_Grade_Level_SortResize.jpg?generation=1586207935460776\&alt=media)

**What is this expression doing?**

If the current grade level is "TK", then output `-1`. If the current grade level is "K", then output `0`.\
Otherwise, output the integer value of the current grade level.

Refer to [**Basics of Writing Expressions in JSS**](https://github.com/christineolah/illuminate-bi-tool-guide/tree/6c2ef197cc28ebf3e67d3eaa4e8ec3be06367b71/tutorials/tutorial-2-using-report-bands/basics-of-writing-expressions-in-jss.md) for detailed documentation on writing expressions in JSS.

#### Create a Sort Field

Now, we need to sort our data using this "Grade Level Numeric" variable that we just created.

* Navigate to the **Outline** tab
* **Right-click** on **Sort Fields**
* Select **Create Sort Field**
* Select **Grade Level Numeric**
* Click Finish

![](https://950445536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4GLkzIBhRPJYBUJD8p%2F-M4GLmpngX5uSfgbRicS%2F-M4GLzT14n8UPaSYhCBa%2FTutorial_2_Pro_Version_Create_Grade_Level_Sort_FieldResize.jpg?generation=1586207935753016\&alt=media)

#### Remove Sorting (a.k.a "Order") Default from Chart

Finally, we need to remove the sorting from the chart. By default, HTML5 Charts will re-sort your data, based on your Category Level. In this case however, we are pre-sorting the data using the "Grade Level Numeric" variable, so we need to tell the chart ***not*** to re-sort our data.

**Double-click** on the chart

* Click **Chart Data > Configuration**
* **Double-click** on the "Grade Level" category level (or click **Modify**)
* Change the **Order** field from "Ascending" to **"None"**
* Click **Finish**

![](https://950445536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4GLkzIBhRPJYBUJD8p%2F-M4GLmpngX5uSfgbRicS%2F-M4GLzT3E4y2uYqMmQRS%2FTutorial_2_Pro_Version_Set_Order_to_NoneResize.jpg?generation=1586207935623469\&alt=media)

**Preview your report.** The grade levels should now be sorting correctly.

![](https://950445536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4GLkzIBhRPJYBUJD8p%2F-M4GLmpngX5uSfgbRicS%2F-M4GLzT5c4HO8_Plsm29%2FTutorial_2_Pro_Version_Preview_Grade_Levels_SortedResize.jpg?generation=1586207935355992\&alt=media)

&#x20;**Did you know Illuminate can build your BI Tool for you?**\
[Click here to learn about Illuminate's **Report Building Service**.](https://www.illuminateed.com/resources/report-building-service/)
