How it works...

In this recipe, we compared the revenue growth rate from one month to the next. As shown by the data, the revenue per month is growing by a steady amount of 100 per month. However, after an initial jump, this steady growth represents a declining percentage of the overall revenue for the company, indicating that the growth is slowing down over time.

We start by simply getting the values for the current month, __ThisMonth, current year, __ThisMonthYear, and the revenue, __ThisMonthRevenue. Then, we need to find these same values for the previous month so that we can compare these values. For __LastMonth, we simply check if the current month is December (12) and if so, we set this variable to January (1); otherwise, we simply subtract 1 from our month number, __ThisMonth, to get the previous month number. Similarly, for __LastMonthYear, we check if the current month is January (1) and if so, we set this to our current year, __ThisMonthYear, minus one since our previous month would be December of last year. Otherwise, we know that the year is the same as our current month, __ThisMonthYear.

Calculating the previous month's revenue, __LastMonthRevenue, is slightly trickier. Since this measure is used within a visualization that only has a single month in the context at any one time, we must use ALL to override this context and include all the rows of the table within our calculation context. Then, we FILTER all of these rows down to only the row(s) that we desire, which in this case is the row that has a value in the MonthNum column equal to our previously calculated __LastMonth and a value in the Year column equal to our previously calculated __LastMonthYear. Then, we can use the SUMX function to sum the Revenue column values across these rows (in this case, just a single row) to arrive at a value for the previous month's revenue, __LastMonthRevenue.

Finally, we simply need to return the comparison between our current month revenue, __ThisMonthRevenue, and last month's revenue, __LastMonthRevenue, as a percentage. We do this using the DIVIDE function, which divides the difference between this month's and last month's revenue by last month's revenue. This provides a percentage increase or decrease for our current month compared to the previous month.