2020: Week 38 - Solution
Solution by Tom Prowse and you can download our solution here.
Step 1 - Split Words
Our table now looks like this:
Now we have the length of the strings we can now join the Scaffold data set. We are going to join where the Length field is greater than or equal to the Scaffold, so we will get an extra row depending on how many letters each word has:
With the additional rows, we now want to use the MID function to identify each of the different letters depending on their position within the word.
Word 1
MID([Word 1],[Scaffold],1)
This will effectively split each of the letters onto an individual row, so our table now looks like this:
Step 2 - Total Letters per Word
The next step is to identify how many of each character each of the words have. Before we do this, we want to duplicate the Word 1 field as we will need to use this twice within the next aggregation step, In the aggregation we want to Group By Row ID & Word 1, then Count Word 1:
After the aggregation step, we now know how many letters are in each of the different words of each row:
This is the end of the Word 1 branch, therefore you will need to repeat these steps but this time for Word 2.
Once you have completed this for both words, it's time to join these two tables together. For this join we want to use a Full Join, this means that we are going to include everything from both tables, even if there are no matches. The join setup looks like this:
Step 3 - Is it an Anagram?
Now we have split each of the characters into a row for each of the words and joined them back together, it's time to identify whether each of the words is an anagram or not.
First, we want to identify whether we have any null values in our Row ID-1 field. If this field is null then we want to give it a 1, else 0:
Row ID-1 Null
IF ISNULL([Row ID-1]) THEN 1
ELSE 0
END
We can then use this field to calculate how many rows are null by using an aggregation tool with the following setup:
We have now identified whether each of the words is an anagram or not so our table looks like this:
The final step this week is to bring back all of the original words from the Anagrams data set, and join these on our table using the Row ID: