2023: Week 9 - Solution
Solution by Tom Prowse and you can download the workflow here.
This is the first week of our advanced week! Building on the previous 2 months we're looking to extend our knowledge even further and look into some of the techniques that are a little harder to complete.
For the challenge we want to identify what the bank balance for a customer is after each transaction and to create a bank statement.
Please note that there have been some problems with this workflow in Tableau 2022.4, so you may need to go to an older version if you are getting unexpected errors.
Step 1 - Combine Transaction Details & Path
For the Transaction Details we want to filter to exclude 'Y' from the 'Cancelled?' field and then remove the 'Cancelled?' field.
We are then ready to join our tables together using an inner join on Transaction ID.
Our table should now look like this:
Step 2 - Transactions In & Out
We now need to split the transactions into incomings and outgoings. For this we want to create two separate branches - 1, Incoming Transactions where we remove the Account From field, 2, Outgoing Transactions where we remove the Account To field and also make the values negative by multiplying by -1.
We can then include the final input, Account Information, into the workflow as a third branch. Within the input we only need to keep the Account Number, Balance Date, and Balance fields.
After this we can bring all of these back together with a union so we have three fields - Account Number, Balance Date, & Balance:
Step 3 - Transaction Order
Next we want to identify the order in which the transactions occurred so that we can then start to calculate the balance at each stage.
To order the transactions we can use a Rank calculation where we group by Account Number, and rank the Balance Date (Ascending) and Balance (Descending):
Due to those extra combinations we need to aggregate the table to calculate the running sum. In the aggregation we want to group by Transaction Order, Account Number, Balance Date, and Transaction Value and then Sum the Transaction Value-1 field.
After the aggregation we just need to tidy some of the fields up with some calculations:
This will round the balance field to 2 decimal places.
We can then make sure that the opening transaction value is null as per the requirements:
We can then remove the Transaction Order and Transaction Value-1 fields and we are ready to output.