2023: Week 10 - Solution
Solution by Tom Prowse and you can download the workflow here.
Building on our challenge from last week, we want to take this a step further and allow users to find out their balance, even on days that they don't make a transaction.
Step 1 - Balance Each Day
After tidying some fields, we want to rename the Total Transaction Value to Transaction Value and the table should look like this:
Step 2 - Next Transaction
Next we need to identify the 'gap' in days between transactions so that we can scaffold the missing days.
For this we want to calculate the transaction order for each Account Number using a Rank calculation:
After the calculation, we can remove the Balance Date and the new clean step table should look like this:
We can now create the self-join to align the current and previous orders using a Left-Inner Join on Account Number and Transaction Order.
Our new table now looks like this:
The last action we need to take at this stage is to ensure that are no null dates within the Balance Date Upper Bound field. If there are nulls we want to replace them with the latest date in the upper bound field.
Therefore we first need to identify the latest date using a LOD:
Then use an IF statement to replace the nulls:
Our table should now look something like this:
Step 3 - Scaffold Table
As a result we should start to generate some rows that look like this:
Then finally we need to ensure that the transaction value is null on the days that no transaction was made.
When we remove the unneeded fields our table should now look like this:
Step 4 - Date Selection Parameter
The final task for this week is to create a date parameter so that the user can select a date to show the balances on this day.
First, we need to duplicate the Date field and then convert it to a string. We can then create a parameter that is a string with a list of dates that you want the user to select. Unfortunately, there is no option to auto-fill these dates based on a field like you can in Tableau Desktop and no Date option so that's why we're using a string!
From here we can use this parameter within a filter where [Parameters.Select a date]=[Date-1]
Then remove both date fields and add the parameter into the Output so that the table name is 'Balance as of <Select a Date>'. This will change the name of the output based on the parameter selected by the user:
Our final table should look like this where 2023-02-01 is selected: