Automate Student Exam Grading with Excel Power Query

Automate Student Exam Grading with Excel Power Query

Using append­ing in Pow­er Query offers a stream­lined approach to auto­mat­i­cal­ly grade stu­dent exams based on pre­de­fined thresh­olds. This method elim­i­nates man­u­al grad­ing errors and saves sig­nif­i­cant time when pro­cess­ing large sets of stu­dent scores, pro­vid­ing an effi­cient way to man­age aca­d­e­m­ic assessments.

The tech­nique com­bines stu­dent scores with grade thresh­olds to gen­er­ate accu­rate results that can be eas­i­ly updat­ed when grad­ing cri­te­ria change.

Watch my step-by-step tuto­r­i­al on how to imple­ment this grad­ing sys­tem using Pow­er Query:

Understanding the Grading Process with Power Query

Pow­er Query’s append­ing fea­ture allows us to com­bine mul­ti­ple tables in a way that cre­ates rela­tion­ships between stu­dent scores and grade thresh­olds. The append­ing process essen­tial­ly stacks tables on top of each oth­er, cre­at­ing a sin­gle dataset that we can manip­u­late to auto­mat­i­cal­ly assign grades. This approach is par­tic­u­lar­ly use­ful in edu­ca­tion­al set­tings where instruc­tors need to process mul­ti­ple exam results efficiently.

The pri­ma­ry advan­tage of using this method is that when grad­ing cri­te­ria change, you don’t need to man­u­al­ly reas­sign grades to each stu­dent. Sim­ply update the thresh­old val­ues in your source table, refresh the query, and all grades will auto­mat­i­cal­ly update to reflect the new standards.

Required Resources

Before start­ing the grad­ing process, you’ll need two essen­tial tables:

  • A table con­tain­ing stu­dent names and their exam points
  • A table defin­ing grade thresh­olds (what point ranges cor­re­spond to which let­ter grades)

These tables will serve as the foun­da­tion for our auto­mat­ed grad­ing sys­tem. The struc­ture of these tables does­n’t need to be complex—just clear­ly orga­nized with appro­pri­ate head­ers to iden­ti­fy the data.

Setting Up the Tables in Power Query

To begin imple­ment­ing the grad­ing sys­tem, we need to import both tables into Pow­er Query. This process allows us to manip­u­late and com­bine the data efficiently.

First, with the stu­dent scores table select­ed, nav­i­gate to the Data tab in Excel. From there, select “From Table/Range” to import the first table into Pow­er Query. When prompt­ed to load the data, choose “Cre­ate Con­nec­tion Only” as we’ll be manip­u­lat­ing this data fur­ther before bring­ing it back to Excel.

Repeat the same process for your grade thresh­olds table. Hav­ing both tables acces­si­ble in Pow­er Query is essen­tial for the next step where we’ll com­bine them through appending.

Appending the Tables

Once both tables are in Pow­er Query, we can com­bine them using the append function:

On the Home tab with­in Pow­er Query Edi­tor, click the Append Queries but­ton (not “Append Queries as New”). In the dia­log box that appears, con­firm that you want to append just the two tables you’ve import­ed. Select the stu­dent table as your pri­ma­ry table and the grades thresh­old table as the table to append.

After append­ing, you’ll notice that the result­ing table con­tains all rows from both orig­i­nal tables. The stu­dent data appears first, fol­lowed by the thresh­old data. This com­bined dataset gives us every­thing we need to assign grades automatically.

Organizing and Sorting the Data

For our grad­ing sys­tem to work prop­er­ly, we need to sort the append­ed data by the num­ber of points. This sort­ing is a cru­cial step because it allows us to arrange scores in ascend­ing order, mak­ing it eas­i­er to assign appro­pri­ate grades.

Click on the col­umn con­tain­ing the points/scores and sort from A to Z (ascend­ing). This action arranges all scores from low­est to high­est, with the grade thresh­olds inte­grat­ed among the stu­dent scores based on their point values.

Because of how the data is now arranged, the grade thresh­olds appear at posi­tions where they nat­u­ral­ly divide the stu­dent scores into dif­fer­ent grade categories.

Assigning Grades Automatically

With our data prop­er­ly sort­ed, we can now use a sim­ple but pow­er­ful tech­nique to assign grades to each stu­dent. The key to this process is the Fill Down com­mand in Pow­er Query.

The grade col­umn ini­tial­ly has val­ues only in the rows that came from our thresh­old table. To assign these grades to stu­dents, select the grade col­umn and nav­i­gate to the Trans­form tab. Click on “Fill” and then “Down.” This action copies each grade down to all rows below it until anoth­er grade is encountered.

As a result, each stu­dent row is auto­mat­i­cal­ly assigned the grade cor­re­spond­ing to their score based on the defined thresh­olds. For exam­ple, if the thresh­old for grade C is 40 points, stu­dents with 40 or more points (but below the next thresh­old) will be assigned a C.

Filtering and Finalizing the Results

After fill­ing down the grades, we need to fil­ter out the thresh­old rows to see only the stu­dent results:

Click the fil­ter but­ton on the col­umn con­tain­ing stu­dent names and select “Fil­ter out emp­ty val­ues” or specif­i­cal­ly select only the rows con­tain­ing actu­al stu­dent data. This leaves us with just the stu­dent infor­ma­tion and their cor­re­spond­ing grades.

With the data fil­tered and grades assigned, we can now load this infor­ma­tion back to Excel. Nav­i­gate to the Home tab and select “Close & Load To.” Choose where you want to place the results in your workbook.

Updating Grades When Thresholds Change

One of the most pow­er­ful aspects of this approach is how eas­i­ly you can adjust grad­ing criteria:

If you need to change the grad­ing thresh­olds, sim­ply update the val­ues in your orig­i­nal thresh­old table. For exam­ple, you might change the min­i­mum score for an A from 90 to 88 points. After mak­ing these changes, save your file and then refresh the query (right-click on your results table and select “Refresh”).

The entire grad­ing process will auto­mat­i­cal­ly run again with the new thresh­olds, updat­ing all stu­dent grades accord­ing­ly. This makes the sys­tem extreme­ly flex­i­ble and saves sig­nif­i­cant time when adjust­ments are needed.

Real-World Application Example

In my video demon­stra­tion, I showed how this sys­tem works with a sam­ple dataset. For instance, Jen­nifer earned 13 points which result­ed in an F grade, Robert received 34 points also result­ing in an F, while Olivia scored 40 points which met the thresh­old for an E grade.

After chang­ing the thresh­olds and refresh­ing the query, the grades updat­ed auto­mat­i­cal­ly to reflect the new stan­dards. This dynam­ic updat­ing capa­bil­i­ty is what makes this approach so valu­able for edu­ca­tors who may need to adjust grad­ing scales based on class per­for­mance or oth­er factors.

How to Clean one column based on the other column

How to Clean one column based on the other column

Pow­er Query offers pow­er­ful solu­tions for clean­ing data across columns by lever­ag­ing infor­ma­tion con­tained in relat­ed columns. In this arti­cle, I’ll demon­strate how to effi­cient­ly remove cryp­tocur­ren­cy sym­bols from a name col­umn when those sym­bols already exist in a sep­a­rate col­umn, even when the sym­bols have vary­ing lengths.

This tech­nique is par­tic­u­lar­ly valu­able when deal­ing with incon­sis­tent data for­mats that require stan­dard­iza­tion for analysis.

Watch my step-by-step tuto­r­i­al video to see these tech­niques in action:

Understanding the Data Cleaning Challenge

When work­ing with finan­cial data, espe­cial­ly cryp­tocur­ren­cy infor­ma­tion, you’ll often encounter datasets where the same infor­ma­tion appears redun­dant­ly across mul­ti­ple columns. In my exam­ple, I have a table con­tain­ing cryp­tocur­ren­cy data where the name col­umn includes both the cryp­tocur­ren­cy name and its sym­bol (like “Bit­coin BTC”), while a sep­a­rate sym­bol col­umn already con­tains just the sym­bol (“BTC”).

The chal­lenge lies in clean­ing the name col­umn by remov­ing these redun­dant sym­bols. What makes this par­tic­u­lar­ly tricky is that cryp­tocur­ren­cy sym­bols vary in length — some might be three char­ac­ters (BTC), oth­ers four (DOGE) or more. This incon­sis­ten­cy means we can’t sim­ply remove a fixed num­ber of char­ac­ters from the end of each name.

Preparing the Data in Power Query

To begin the clean­ing process, we need to load our data into Pow­er Query where we can apply the nec­es­sary transformations:

  1. Nav­i­gate to the Data tab in Excel
  2. Select your data range and choose to load it to Pow­er Query
  3. Remove any unnec­es­sary columns to focus on the task at hand

In my case, I ini­tial­ly removed sev­er­al columns to focus on just the key columns for this demon­stra­tion — the name col­umn con­tain­ing both cryp­tocur­ren­cy names and sym­bols, and the sym­bol col­umn con­tain­ing just the sym­bols. This sim­pli­fied approach allows us to con­cen­trate specif­i­cal­ly on the clean­ing tech­nique with­out distraction.

Solution #1: Using Text After Delimiter

The first solu­tion uses Pow­er Query’s built-in func­tions to extract the rel­e­vant part of the text. This approach is more straight­for­ward and uses the UI-based options:

To imple­ment this solution:

  1. Select the name col­umn in Pow­er Query
  2. Go to the Add Col­umn tab
  3. Choose Extract and then Text After Delimiter

Ini­tial­ly, when using the UI, you might try enter­ing a spe­cif­ic sym­bol like “BTC” as the delim­iter. How­ev­er, this would only work for one cryp­tocur­ren­cy. The real pow­er comes from mod­i­fy­ing the for­mu­la to use the sym­bol col­umn as a reference.

After cre­at­ing the ini­tial for­mu­la, you’ll need to edit it in the for­mu­la bar to make it dynam­ic. Replace the hard­cod­ed delim­iter text with a ref­er­ence to the sym­bol col­umn. This way, Pow­er Query will use each row’s cor­re­spond­ing sym­bol to extract just the cryp­tocur­ren­cy name, regard­less of the sym­bol­’s length.

Solution #2: Using Text.RemoveRange Function

The sec­ond solu­tion is more com­plex but demon­strates the flex­i­bil­i­ty of Pow­er Query’s M lan­guage. For this approach:

  1. Go to the Add Col­umn tab
  2. Select Cus­tom Column
  3. Use the Text.RemoveRange func­tion to pre­cise­ly remove the sym­bol part

The for­mu­la will look some­thing like:

Text.RemoveRange([name], 0, Text.Length([symbol]))

This func­tion works by remov­ing a spe­cif­ic range of char­ac­ters from the text. It requires three parameters:

  • The source text (our name column)
  • The start­ing posi­tion (0‑based in Pow­er Query)
  • The num­ber of char­ac­ters to remove (which we deter­mine using the length of the symbol)

Remem­ber that Pow­er Query uses zero-based index­ing, mean­ing the first char­ac­ter posi­tion is 0, not 1. This is cru­cial when work­ing with text manip­u­la­tion functions.

Finalizing the Transformation

After apply­ing either solu­tion, we need to clean up our query:

  1. Rename the new­ly cre­at­ed col­umn to some­thing mean­ing­ful (like “name”)
  2. Delete the orig­i­nal name col­umn that con­tained the symbols
  3. If need­ed, restore any pre­vi­ous­ly removed columns by delet­ing the “Removed Columns” step
  4. Arrange columns in the desired order by drag­ging them

In my exam­ple, I also demon­strat­ed how to clean anoth­er col­umn (cir­cu­lat­ing sup­ply) that had a sim­i­lar issue but with a sim­pler pat­tern. Since all the unwant­ed sym­bols in this col­umn were pre­ced­ed by a space, I could use the Extract Text Before Delim­iter func­tion with a space as the delimiter.

Loading the Cleaned Data Back to Excel

Once all trans­for­ma­tions are com­plete, we can load the cleaned data back to Excel:

  1. Go to the Home tab in Pow­er Query
  2. Select Close & Load To
  3. Choose whether to load to a new work­sheet or an exist­ing location

In my demon­stra­tion, I loaded the data to cell A13 on the exist­ing work­sheet, which allows for easy com­par­i­son between the orig­i­nal and cleaned data.

Why This Approach Matters

The beau­ty of using Pow­er Query for this type of data clean­ing is that it cre­ates a repeat­able process. If your data source updates, you can sim­ply refresh the query, and all the clean­ing steps will be reap­plied auto­mat­i­cal­ly. This saves sig­nif­i­cant time com­pared to man­u­al clean­ing or using for­mu­las that would need to be copied down for each new set of data.

Addi­tion­al­ly, by lever­ag­ing infor­ma­tion from one col­umn to clean anoth­er, we cre­ate a more robust solu­tion that can han­dle vari­a­tions in the data for­mat with­out break­ing. This approach is far supe­ri­or to hard-cod­ing spe­cif­ic text val­ues or char­ac­ter counts that might change across dif­fer­ent datasets.

How to Remove Empty Columns in Excel with Power Query (Automated Method)

How to Remove Empty Columns in Excel with Power Query (Automated Method)

In this guide, I’ll show you how to auto­mat­i­cal­ly remove com­plete­ly emp­ty columns in your Excel data using Pow­er Query. This pow­er­ful tech­nique saves you from tedious man­u­al dele­tion and works even when columns con­tain null val­ues, emp­ty cells, and emp­ty text strings (rep­re­sent­ed by “”).

The approach I’ll demon­strate uses a spe­cif­ic Pow­er Query for­mu­la that iden­ti­fies and removes columns with no mean­ing­ful data, great­ly improv­ing your data clean­ing workflow.

Watch my detailed video walk­through of this process:

Understanding Empty Columns in Power Query

When work­ing with data in Excel, we often encounter columns that appear emp­ty but can actu­al­ly con­tain dif­fer­ent types of “empti­ness” that Pow­er Query rec­og­nizes dif­fer­ent­ly. It’s impor­tant to under­stand that Pow­er Query dis­tin­guish­es between null val­ues (tru­ly emp­ty cells), and cells con­tain­ing emp­ty text strings (“”).

An emp­ty text string occurs when a cell con­tains a for­mu­la that returns “” or when you paste such val­ues. These look emp­ty visu­al­ly in Excel, but Pow­er Query treats them dif­fer­ent­ly than cells with null val­ues. Our goal is to cre­ate a solu­tion that iden­ti­fies and removes columns regard­less of which type of “empti­ness” they con­tain, as long as the entire col­umn con­tains no mean­ing­ful data.

Importing Data into Power Query

To begin the process of remov­ing emp­ty columns, we first need to import our data into Pow­er Query. Here’s exam­ple how to do this:

  1. Go to the Data tab in Excel
  2. Click on “Get Data” → “From File” → “From Excel”
  3. Locate and select your Excel file
  4. Choose the work­sheet con­tain­ing your data (in my exam­ple, Sheet1)

After import­ing, you’ll notice that some columns might appear emp­ty but con­tain dif­fer­ent types of empti­ness — some cells might have null val­ues (shown as “null” in Pow­er Query), while oth­ers might be tru­ly emp­ty or con­tain emp­ty text strings. Our code will han­dle all these sce­nar­ios automatically.

The Power Query Solution

Rather than man­u­al­ly delet­ing emp­ty columns, we’ll use a cus­tom for­mu­la in Pow­er Query that auto­mat­i­cal­ly iden­ti­fies and removes all emp­ty columns. This approach is much more effi­cient, espe­cial­ly when work­ing with large datasets.

The Complete Code

Here’s the com­plete Pow­er Query for­mu­la that we’ll use to remove emp­ty columns:

= Table.RemoveColumns(#“Changed Type”, List.Select( Table.ColumnNames(#“Changed Type”), each List.Count( List.RemoveMatchingItems( Table.Column(#“Changed Type”, _), {null, “”} ) ) = 0 ) )

To use this code in your own projects, you’ll need to replace #“Change Type” with the name of your pre­vi­ous step in Pow­er Query. This ref­er­ence appears in three places in the for­mu­la, so be sure to update all instances.

Breaking Down the Formula

Let’s break down this for­mu­la to under­stand how it works:

The for­mu­la starts with Table.RemoveColumns(), which is the func­tion that will even­tu­al­ly remove our emp­ty columns from the table. This func­tion takes two para­me­ters: the table we’re work­ing with, and a list of col­umn names to remove.

To gen­er­ate the list of col­umn names to remove, we use List.Select(), which fil­ters a list based on a con­di­tion. We’re fil­ter­ing the list of all col­umn names (obtained using Table.ColumnNames()) to find those that meet our “emp­ty col­umn” criteria.

The core log­ic hap­pens in this part:

List.Count(List.RemoveMatchingItems(Table.Column(#“Change Type”, _), {“”, null})) = 0

For each col­umn, we:

  1. Extract all val­ues in the col­umn using Table.Column()
  2. Remove any val­ues that are emp­ty strings or null using List.RemoveMatchingItems()
  3. Count how many items remain using List.Count()
  4. Check if this count equals zero (mean­ing the col­umn is com­plete­ly empty)

If the count equals zero, the col­umn is con­sid­ered emp­ty and will be includ­ed in our list of columns to remove.

Implementing the Solution

To imple­ment this solu­tion in your Pow­er Query Editor:

  1. Click “Add Step” to cre­ate a new trans­for­ma­tion step
  2. In the for­mu­la bar, paste the com­plete code shown above
  3. Replace “#“Change Type”” with the name of your pre­vi­ous step (typ­i­cal­ly the step after pro­mot­ing headers)
  4. Press Enter to apply the transformation

You should now see your data with all emp­ty columns removed. The trans­for­ma­tion hap­pens imme­di­ate­ly, leav­ing only columns that con­tain at least one non-emp­ty value.

Testing the Solution

To ver­i­fy that our solu­tion works cor­rect­ly, we can test it with dif­fer­ent types of data. In my video, I demon­strat­ed this by:

1. Start­ing with a dataset that con­tained sev­er­al emp­ty columns (with var­i­ous types of emptiness)

2. Apply­ing our Pow­er Query solu­tion to remove these columns

3. Mod­i­fy­ing the source data to add a new col­umn with a sin­gle value

4. Refresh­ing the query to ver­i­fy that the col­umn with a val­ue is preserved

The solu­tion cor­rect­ly iden­ti­fied and retained columns that had at least one mean­ing­ful val­ue, while remov­ing columns that were com­plete­ly empty.

Advanced Usage and Adaptations

This solu­tion can be eas­i­ly adapt­ed to work with dif­fer­ent datasets. The key is to ensure you’re ref­er­enc­ing the cor­rect pre­vi­ous step in your Pow­er Query trans­for­ma­tion sequence. If your pre­vi­ous step is named dif­fer­ent­ly, sim­ply replace all instances of “#“Change Type”” with the appro­pri­ate step name.

When work­ing with very large datasets, this auto­mat­ed approach can save sig­nif­i­cant time com­pared to man­u­al­ly iden­ti­fy­ing and remov­ing emp­ty columns. Addi­tion­al­ly, the solu­tion is dynam­ic — if your source data changes and a pre­vi­ous­ly emp­ty col­umn now con­tains val­ues, refresh­ing the query will auto­mat­i­cal­ly retain that column.

Loading the Results

After apply­ing our trans­for­ma­tion, we can load the results back to Excel:

  1. Click “Close & Load” (or “Close & Load To…” if you want to spec­i­fy a destination)
  2. Choose your pre­ferred des­ti­na­tion (work­sheet, data mod­el, etc.)
  3. The cleaned data, with emp­ty columns removed, will be loaded to your spec­i­fied location

The result­ing table will con­tain only mean­ing­ful columns that have at least one val­ue. This makes your data more con­cise and eas­i­er to work with.

When your source data changes, sim­ply refresh the query to apply the same trans­for­ma­tions to the updat­ed data. The emp­ty col­umn removal log­ic will be reap­plied auto­mat­i­cal­ly, adapt­ing to any changes in your source data’s structure.