Skip to main content

CAGR Dax Measure




CAGR stands for Compound Annual Growth Rate.  It describes the rate at which an investment would have grown over several years if it had grown at the same rate every year on a compounding, rather than simple, basis. 

The CAGR metric is calculated using the following formula:

If we were to fit this entire formula into a single measure it may get messy and confusing for other users, so let’s step it out.

We will need to create several measures to calculate the individual pieces the CAGR formula.  Of course, this is not the only way to calculate CAGR in Power Pivot, but this is the way we’ve decided to go about it.  So, let’s break it down, we will need the following measures to calculate CAGR:

  1. A measure to retrieve the First Year in the data set
  2. A measure to retrieve the Last Year in the data set
  3. A measure to calculate the Number of Years between the First and Last Years in the data set
  4. A measure to aggregate the total sales in the data set
  5. A measure to calculate the Sales in the First Year of the data set
  6. A measure to calculate the Sales in the Last Year of the data set
  7. Finally, a measure to calculate CAGR. 

The [First Year] measure is calculated as follows: 

=MIN('Calendar'[Year])

The [Last Year] measure is very similar:

=MAX('Calendar'[Year])

The [Number of Years] measure is simply calculated as the difference between the two years.  Unlike calculating dates, you need to resist the urge of adding one to this calculation as there is only one year’s growth between the first year and the next year, etc.

=[Last Year]-[First Year]

The sales aggregation measure is given by [Sales]:

=SUM('Sales Table'[Total Sales])

To calculate the [Sales in First Year] measure:

=CALCULATE(

[Sales],

                        FILTER(

                                    'Calendar','Calendar'[Year]=[First Year]

                        )

 

            )

There is therefore no surprise (hopefully!) that [Sales in Last Year] measure is calculated as follows:

=CALCULATE(

            [Sales],

                        FILTER(

                                    'Calendar','Calendar'[Year]=[Last Year]

                        )

 

            )

The [CAGR] measure is thus given by:

=([Sales in Last Year]/[Sales in First Year])^(1/[Number of Years])-1

This all seems to make sense.  That should be it: let’s create the PivotTable.  However, trying to plot our CAGR measure on a PivotTable we get the following message:

Something is not right!  Let’s plot the individual measures onto a PivotTable to see if we can figure it out:

It appears that our [First Year] and [Last Year] measures aren’t working as we intended, hence causing our [Number of Years] measure to return with ‘0’ every year.  This causes a division by zero error in our [CAGR] measure.

The first and last year measures return with the row’s first and last year.  This is because these measures are subject to the PivotTable row filters.  We are going to have to tweak the measures for them to consider the entire range of data, despite these row filters.

In this case we will have to use the ALL function.  You can read more about the ALL function here.

We have to modify the first and last year measures.  The [First Year] measure should be revised as follows:

=CALCULATE(

            MIN(

                        'Calendar'[Year]),

                        ALL(

                                    'Calendar'

                        )

            )

Similarly, the [Last Year] measure should be adapted too:

=CALCULATE(

            MAX(

                        'Calendar'[Year]),

                        ALL(

                                    'Calendar'

                        )

            )

Our [CAGR] measure now calculates on the PivotTable: 

Great, we finally have a working CAGR measure! But the measure only calculates the CAGR for the last year, what if we want the progressive CAGR for each year.


The reason why our CAGR formula is not calculating dynamically is because we are using the [Last Year] measure, which is currently set to retrieve the last year in our data set.  To avoid confusion, we are going to create a measure that retrieves the current year called [Current Year]:

=MAX('Calendar'[Year])

Now we modify our [CAGR] measure to use the [Current Year] measure:

=([Sales in Current Year]/[Sales in First Year])^(1/[Number of Years])-1

However, attempting to put our CAGR measure in the Pivot Table will result in this error: 

This is because the number of years for the 2018 period is zero, and we can’t divide by zero.  In this scenario, we should use the DIVIDE function to create our [CAGR Dynamic] new-and-improved measure.  You can read more about the DIVIDE function here:

=DIVIDE(

            [Sales in Current Year],[Sales in First Year]

                        )

                                    ^DIVIDE(

                                                1,[Number of Years]

 

                                                )-1

The DIVIDE function manages our division by zero problem by returning with BLANK() when the denominator is zero.  Therefore, this gives us the dynamic CAGR calculation we require:







<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2735813199391136"
     crossorigin="anonymous"></script>

Comments

Popular posts from this blog

Data Analysis Tool Pack

  The  Analysis ToolPak  is an  Excel add-in  program that provides data analysis tools for financial, statistical and engineering data analysis. To load the Analysis ToolPak add-in, execute the following steps. 1. On the File tab, click Options. 2. Under Add-ins, select Analysis ToolPak and click on the Go button. 3. Check Analysis ToolPak and click on OK. 4. On the Data tab, in the Analysis group, you can now click on  Data Analysis . The following dialog box below appears. 5. For example, select Histogram and click OK to create a Histogram in Excel. Example Rank and Percentile The Rank and Percentile contained within the Analysis-ToolPak can be quickly used to find the rank of all the values in a list. The advantage of using the Rank and Percentile feature is that the percentile is also added to the output table. The percentile is a percentage that indicates the proportion of the list which is below a given number. Highlight the list (or the cells) which...

Indirect Function

INDIRECT  is pretty cool for grabbing a value from a cell. Can  INDIRECT  point to a multi-cell range and be used in a  VLOOKUP  or  SUMIF  function?  You can build an  INDIRECT  function that points to a range. The range might be used as the lookup table in a  VLOOKUP  or as a range in  SUMIF  or  COUNTIF . In  Figure , the formula pulls data from the worksheets specified in row 4. The second argument in the  SUMIF  function looks for records that match a certain date from column A. Note:  Because each worksheet might have a different number of records, I chose to have each range extend to 300. This is a number that is sufficiently larger than the number of transactions on any sheet. The formula in cell B5 is: =SUMIF(INDIRECT(B$4&"!A2:A300"), $A5, INDIRECT(B$4&"!C2:C300")) Summary:  You can use  INDIRECT  to grab data from a multi-cell range.

Data Model an easy substitute for Vlookup

  you have a data set with product, date, customer, and sales information. The IT department forgot to put sector in there. Here is a lookup table that maps customer to sector. Time for a VLOOKUP, right? There is no need to do VLOOKUPs to join these data sets if you have Excel 2013 or newer. These versions of Excel have incorporated the Power Pivot engine into the core Excel. (You could also do this by using the Power Pivot add-in for Excel 2010, but there are a few extra steps.) In both the original data set and the lookup table, use Home, Format as Table. On the Table Tools tab, rename the table from Table1 to something meaningful. I’ve used Data and Sectors. Select one cell in the data table. Choose Insert, Pivot Table. Starting in Excel 2013, there is an extra box, Add This Data to the Data Model, that you should select before clicking OK. The Pivot Table Fields list appears, with the fields from the Data table. Choose Revenue. Because you are using the Data Model, a new line a...