2024: Week 32 - Solution


Solution by Tom Prowse and you can download the workflow here.



Step 1 - Combine Cards, Pokémon, and Trainer Cards

First we want to input our tables and combine them together to make a single table.

For this we need to make some changes to the tables to ensure that they combine correctly and so we don't have duplicate values. 

First we can look at the Cards input, where we want to split the Leader and the Pokémon fields from the Name field. The name field should become two fields in the format of: [Name]'s [Pokémon] 

Normally, a custom split will use the 's as a separator however in this case using the ' doesn't work so therefore we can write out two separate calculations instead: 

Leader
TRIM(SPLIT([name],"'s",1))

Pokémon 
TRIM(SPLIT([name],"'s",2))

The Pokémon Cards table will now look like this with the additional fields: 


Now we can focus on the 2nd input which is the Pokémon table. For this we need to ensure that we have a single row for each Pokédex # and Name combination. We aren't worried about the other stats so we can just group by these two fields within an Aggregation step: 



Then we can join these tables together using an inner join where Pokémon = Name:



At this stage the table should look like this: 



Then finally we can combine the 3rd table - Training Cards. For this we want to 'stack' these on top of the existing table therefore we using a Union instead of a Join. Some of the fields are missing from the Trainer table so some Null values appear but the table should then look like this: 



Step 2 - Card Type 

Now we want to identify the difference between a Pokémon and a Trainer. For this we can use the Table Names field that is created by the Union step and extract the information from here.

For this we want to split off the value after the last '/' which will provide this information: 



We can then use this field and remove the 'Cards' section by using another split to only return the first word before the ' ' (space) for each row: 



We can then remove any unneeded fields and rename the split field to Card Type. We can also tidy the Leader field by replacing any Null values with 'Leftover Trainers'.

The table should now look like this: 


Step 3 - Card Classifying & Order

Finally we want to classify the cards and order them as per the requirements. For this we want to combine the Leader Order table by using an inner join on Leader:


We can then classify the cards based on the given requirements: 

Card Classifying 
IF [Card]=[Leader]
THEN 1
ELSEIF CONTAINS([Card],'Gym') and [Leader]!='Leftover Trainers'
THEN 2
ELSEIF [Card Type]='Trainer'
THEN 3
ELSE 4
END

Then we can use this classification to sort the cards into the correct order: 



We can then remove any fields that aren't required and our output should look like this: 



You can view the output here.

After you finish the challenge make sure to fill in the participation tracker, then share your solution on Twitter using #PreppinData and tagging @Datajedininja@JennyMartinDS14 & @TomProwse1

You can also post your solution on the Tableau Forum where we have a Preppin' Data community page. Post your solutions and ask questions if you need any help! 

Popular posts from this blog

2023: Week 1 The Data Source Bank

2024: Week 1 - Prep Air's Flow Card

How to...Handle Free Text