Please note javascript is required for full website functionality.

Blog

Power Query: Revision Time – Part 12

26 June 2024

Welcome to our Power Query blog.  Today, I continue to create a refreshable revision timetable by randomising the subject slots I need for the timetable.

 

As my salespeople take a well-earned break, many students here in the UK are preparing for exams in the summer.  To help my own offspring get organised, I volunteered to create a refreshable printable revision timetable.  This is the result:

I needed a list of topics, and to begin with, I created extra entries for topics that required more timeslots:

We agreed on half-hourly slots, and I created a grid so that my daughter could indicate the slots that she wouldn’t be able to revise. 

When I first designed the solution, I included some Excel functions, but since this is a Power Query blog, I will ensure that I only use Power Query functions (apart from some formatting at the end!).

In Part 1, I converted my data into two [2] Tables: Subjects and Availability.  I extracted Subjects to Power Query.

I created the Availability query by taking a copy of Subjects, and amending it:

In Part 2, and Part 3, I calculated the number of subjects and the number of slots on Availability.

This gave me both totals:

In Part 4, I calculated how many times each subject will appear in a new query, remembering to round up to whole slots.

This told me the number of slots that each subject should have for my example is three [3]:

In Part 5, I created a table where each subject appeared three times (i.e. the number of times given by Subject_Slots).  

In Part 6, I randomised the order of the slots ready to add to the timetable:

In Part 7, I took a reference copy of the query Availability which I called TimeTable and began to transform it so that it is ready to receive the slot data.

In Part 8, I appended the slot number data to the rest of the TimeTable query.

In Part 9, I removed the duplicate values. 

However, as I said in Part 8, I could have transformed the data in TimeTable by merging instead of appending, and I looked at that in Part 10:

Last time, I merged TimeTable with the Random_Subject query, and transformed the result to get the final TimeTable query:

I choose ‘Close & Load To…’ from the ‘Close & Load’ dropdown in the Home tab.  This is because I don’t want to load all the queries to the workbook. 

This takes me back to the workbook and prompts me with a dialog.  I choose ‘Only Create Connection’, as I will choose the query I wish to load individually:

I then right-click on TimeTable to access the dialog again:

I choose to load it to a new worksheet, so that I may print it out:

I can format my table using ‘Conditional Formatting’:

I have chosen a dark grey fill and no text to appear for those cells containing ‘x’:

I can refresh to change the random generation of subject slots, and when my daughter can revise during the day, I simply remove some of the ‘x’ values:

Then, I refresh the TimeTable Query:

The timetable is updated with more slots.

My timetable is working as required, and ready to be ignored!

 

Come back next time for more ways to use Power Query!

Newsletter