Power Query: Riveting Results Part 1
15 December 2021
Welcome to our Power Query blog. This week, I look at an example where I plan to use parameters.
My salespeople are taking a break. This week, I am looking at some exam results:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I will be grading the results and I will be using this example to explore parameters. I’ll start by extracting my data into Power Query, where I will create the grade column. To extract my data, I choose ‘From Table/Range’ from the ‘Get & Transform’ section of the Data tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
I have called my query Exam Results. I will begin by creating a Conditional Column from the ‘Add Column’ tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I call the new column Grade, and create the grade bands for the results. Each Clause will look at whether the Result ‘is greater than’ a Value, and I will start with the highest grade.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
For now, I will be entering values, but I plan to replace this with parameters later.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I create a Clause for each band.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
Note that, if I miss one, I can add it later and then change the order using the menu next to each Clause.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I click OK to see the new column:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
The M code generated for this step is as follows:
Table.AddColumn(#"Changed Type", "Grade", each if [Result] > 90 then 9 else if [Result] > 80 then 8 else if [Result] > 70 then 7 else if [Result] > 60 then 6 else if [Result] > 50 then 5 else if [Result] > 40 then 4 else if [Result] > 30 then 3 else "Ungraded")
I can change this in the Advanced Editor, which I access from the Home tab. I want to format it so that the boundaries are easier to see. I can split each step over any number of lines, a comma (,) or (as in this case) the ‘in’ statement indicates when the step is complete.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/263/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I am now ready to create some parameters to decide the grades.
Come back next time for more ways to use Power Query!