2023: Week 45 - Solution



Solution by Tom Prowse and you can download the workflow here



Step 1 - Project Name

First we want to separate the project name from the financial transactions in the project field. 

Project Name
IF ISNULL([Cost]) 
AND ISNULL([Invoiced Amount]) 
THEN [Project] 
END

After bringing these project names out into a separate field, you can see that the field contains a lot of null values. This is where we want to create a fill down calculation to fill in the missing nulls. 



Fill down calculations can be found in the ever growing 'Create Calculated Field' menu: 


Like other calculations in Tableau Prep, this is also a visual calculation editor which will aid our understanding of how to set it up. 

Working from left to right: 
1. Group by - how shall we split the calculation. In our case we want to look over the whole table.
2. Order by - what field do we want to use as the sequence? We can utilise the Source Row Number to ensure that we are reading from top to bottom
3. Compute using - this is the field that we want to 'fill in'. We need the project name field here.
4. Results - this is where Tableau Prep gives us an example of what the calculation will create, and also a visual que as to when the 'fill down' changes to a new value (highlighted in blue). 

Our fill down calculation looks like this: 



One thing to note is that you can't overwrite existing fields, so we need to give this a different name then remove Project Name and rename our filled in field.

The last piece of this step is to filter the view so we are only looking at Costs or Invoiced Amounts. We can filter the table using this calculated field: 

NOT ISNULL([Cost]) OR NOT ISNULL([Invoiced Amount])

At this stage our table should look like this: 



Step 2 - Profit

The final stage of this challenge is to calculate the total profit across the accounts. 

First we need to total the Costs and Invoiced Amounts for each Project Name. We can do this using an aggregate step: 



Then we can use these two fields to calculate profit: 

Profit
[Invoiced Amount]-[Cost]


Then we are ready to output our data that looks like this: 



You can download the output from 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

2024: Week 1 - Prep Air's Flow Card

2023: Week 1 The Data Source Bank

How to...Handle Free Text