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:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1715274309.png/9fa4928e14c7422c8be9c83417b61922.jpg)
I needed a list of topics, and to begin with, I created extra entries for topics that required more timeslots:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1715274356.png/2734faf8bb0c4e8f3c8cb772fe0d7ba3.jpg)
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.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1715274377.png/bbef9530a5dd6e6f91072736ed0f9cc7.jpg)
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.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1715274404.png/413d7ef9314ea3ca270945c0b5f5b027.jpg)
I created the Availability query by taking a copy of Subjects, and amending it:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1715274421.png/c10f40de073ab43a9f508ece457af593.jpg)
In Part 2, and Part 3, I calculated the number of subjects and the number of slots on Availability.
This gave me both totals:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1715274443.png/2cfbc9eb1a21686e35d2beb4789969e5.jpg)
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]:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1715274461.png/d917c7c59d5b66cf2219a2c9f1650088.jpg)
In Part 5, I created a table where each subject appeared three times (i.e. the number of times given by Subject_Slots).
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1715274478.png/2a017b84b1e503112bcfaf1e5561eae2.jpg)
In Part 6, I randomised the order of the slots ready to add to the timetable:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image12-1715274671.png/a8ca9f195c1932f5ffa66e4f4ab0c151.jpg)
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.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image13-1715277472.png/32061c33de06fa20fadf085e860e7280.jpg)
In Part 8, I appended the slot number data to the rest of the TimeTable query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image17-1715278202.png/397ea2f7e8ae1320663b671cc2ef24e3.jpg)
In Part 9, I removed the duplicate values.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image15-1715279313.png/020275cd12d7df6385b8bf3895a5d1f5.jpg)
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:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image19-1715280085.png/2fd49ab8a55fdf4f67f659a79519e813.jpg)
Last time, I merged TimeTable with the Random_Subject query, and transformed the result to get the final TimeTable query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image22-1715280863.png/80c94f9ad7ef3b99e61af28d31e64135.jpg)
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.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image15-1715281515.png/9eb2367938723604c1755b06d400eb67.jpg)
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:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image16-1715281547.png/7032265f03c9ee3e56963895af47fdd6.jpg)
I then right-click on TimeTable to access the dialog again:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image17-1715281563.png/c4f403edf5071776455f6cd2c048bd09.jpg)
I choose to load it to a new worksheet, so that I may print it out:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image18-1715281599.png/2978e3f3f7253f0009e7502c597c1b51.jpg)
I can format my table using ‘Conditional Formatting’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image19-1715281622.png/44b9ca36015356b5126c705104173bf8.jpg)
I have chosen a dark grey fill and no text to appear for those cells containing ‘x’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image20-1715281641.png/17ebf7bc62e73f04163b308d85a60d95.jpg)
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:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image21-1715281659.png/b69729a3e359eb9897324f7551a9f17e.jpg)
Then, I refresh the TimeTable Query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image22-1715281675.png/9576c213507ca31f02782486e3677125.jpg)
The timetable is updated with more slots.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image23-1715281692.png/2b0c19d863cc46ead63f845e212653f3.jpg)
My timetable is working as required, and ready to be ignored!
Come back next time for more ways to use Power Query!