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!