Power Query: Revision Time – Part 10
12 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)
Last week, 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. To make it easier to follow, I have created a copy of the earlier steps of TimeTable. This query has been created purely to show the merging technique:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image13-1715279938.png/0f6b1aeaff10f057c1c7afe9cd2d5687.jpg)
I choose ‘Merge Queries’ from the Home tab, and merge TimeTable (Merge Method) with itself. I choose to merge on all columns apart from Slot Number and take the default ‘Left Outer’ join.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image14-1715279958.png/44149b91e3a6987ed65ce3687c434e8c.jpg)
The results are not relevant at this point: I need to change the M code.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image15-1715279976.png/a738f69069ac2bdd97461f4e261bbf85.jpg)
I change the M code from:
= Table.NestedJoin(#"Index Slots Only", {"Time Slot", "Attribute", "Value", "Index"}, #"Index Slots Only", {"Time Slot", "Attribute", "Value", "Index"}, "Index Slots Only", JoinKind.LeftOuter)
to
= Table.NestedJoin(#"Index Full Query", {"Time Slot", "Attribute", "Value", "Index"}, #"Index Slots Only", {"Time Slot", "Attribute", "Value", "Index"}, " Index Slots Only", JoinKind.LeftOuter)
i.e. I am changing the first merge table to the ‘Index Full Query’ step:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image16-1715280036.png/f8f88c33f35f56187b16e92f95ef9763.jpg)
I only need the Slot Number from the expanded Table:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image17-1715280054.png/72ef9490e655642584ff9acf8f856dbd.jpg)
When I click OK, I have the data, but the order is jumbled:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image18-1715280069.png/329f755962f1c5ca9f5b2635b69bbfd5.jpg)
When I sort the data by ascending Index, I can compare it with the append method:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image19-1715280085.png/2fd49ab8a55fdf4f67f659a79519e813.jpg)
I have the same results in the same number of steps, so it only comes down to which method is easier for you!
Next time, I will continue to transform TimeTable.
Come back next time for more ways to use Power Query!