This week we looked at a property management challenge, where we wanted to calculate the amount of rental revenue that our company is making from it's portfolio. The challenge was created by Tom Smith (@tSmithyyy) so let's take a look at how to solve it.
Step 1 - Contract Length
First we want to calculate the length of each contract in months. To do this we want to input the Rental Contracts data then use a DateDiff calculation to find the length of the contract in months:
Then finally we can find the month of the contract start and end month by using the following calculations:
Contract Start Month
DATE(DATETRUNC('month',[Contract Start]))
Contract End Month DATE(DATETRUNC('month',[Contract End]))
At this stage our table should look like this:
Step 2 - Combine Prices
Next we want to combine both the rental contracts and the office space prices tables, by joining them using and inner join on the City and Office Size fields:
From here we can remove any duplicated fields as a result of the join (City-1 & Office Size-1).
Step 3 - Create Rows
We now want to create a new row of data for each month that the property will be rented. To do this we can use the 'New Rows' step within Tableau Prep to help us pad out the missing rows based on the start and end dates.
The New Rows step should have the following setup:
As a result our contract lengths should now be split out so there is a row for each month that the contract is live:
Then after creating the new rows, we need to ensure that the final month isn't included, therefore we need to filter to exclude these values using: [Contract End Month]!=[Month Divider]
After this we can remove the Contract Start and End Month fields from our view.
Step 4 - Cumulative Cost
Next we want to calculate the cumulative cost of each monthly rental space contract. We can calculate this by using the following calculation:
Cumulative Monthly Cost
{ PARTITION [Company] :
{ ORDERBY [Month Divider] ASC : WINDOW_SUM([Rent per Month])}
}
At this stage we have our first output that looks like this:
Step 5 - Total Paid Rent
For the second output we want to calculate the total amount of rent that has been paid across time.
First we need to identify whether the value is from a completed year or needs to be included in a year to date calculation. We can identify these by using the following calculation:
EoY or Current
IF
MAKEDATE(2022,04,13)
>
[Month Divider]
THEN [Rent per Month] END
Then we can convert our Month Divider field into just the Year:
Year
YEAR([Month Divider])
At this stage we are ready to aggregate our table to calculate the totals that are required. Using the aggregation tool we can group by Year and the Sum EoY and Current:
As a result we have our 2nd output that looks like this:
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!
Created by: Carl Allchin Welcome to a New Year of Preppin' Data challenges. For anyone new to the challenges then let us give you an overview how the weekly challenge works. Each Wednesday the Preppin' crew (Jenny, myself or a guest contributor) drop a data set(s) that requires some reshaping and/or cleaning to get it ready for analysis. You can use any tool or language you want to do the reshaping (we build the challenges in Tableau Prep but love seeing different tools being learnt / tried). Share your solution on LinkedIn, Twitter/X, GitHub or the Tableau Forums Fill out our tracker so you can monitor your progress and involvement The following Tuesday we will post a written solution in Tableau Prep (thanks Tom) and a video walkthrough too (thanks Jenny) As with each January for the last few years, we'll set a number of challenges aimed at beginners. This is a great way to learn a number of fundamental data preparation skills or a chance to learn a new tool — New Year...
Created by: Carl Allchin Welcome to a New Year of Preppin' Data. These are weekly exercises to help you learn and develop data preparation skills. We publish the challenges on a Wednesday and share a solution the following Tuesday. You can take the challenges whenever you want and we love to see your solutions. With data preparation, there is never just one way to complete the tasks so sharing your solutions will help others learn too. Share on Twitter, LinkedIn, the Tableau Forums or wherever you want to too. Tag Jenny Martin, Tom Prowse or myself or just use the #PreppinData to share your solutions. The challenges are designed for learning Tableau Prep but we have a broad community who complete the challenges in R, Python, SQL, DBT, EasyMorph and many other tools. We love seeing people learn new tools so feel free to use whatever tools you want to complete the challenges. A New Year means we start afresh so January's challenges will be focused on beginners. We will u...
Free isn't always a good thing. In data, Free text is the example to state when proving that statements correct. However, lots of benefit can be gained from understanding data that has been entered in Free Text fields. What do we mean by Free Text? Free Text is the string based data that comes from allowing people to type answers in to systems and forms. The resulting data is normally stored within one column, with one answer per cell. As Free Text means the answer could be anything, this is what you get - absolutely anything. From expletives to slang, the words you will find in the data may be a challenge to interpret but the text is the closest way to collect the voice of your customer / employee. The Free Text field is likely to contain long, rambling sentences that can simply be analysed. If you count these fields, you are likely to have one of each entry each. Therefore, simply counting the entries will not provide anything meaningful to your analysis. The value is in ...