ExcelChartGaps1

How to Create Excel Charts to Visualize Variances in Stock Performance

If you want to compare and contrast between two sets of values, a chart can help you accomplish that. In this post, I’m going to show you how you can compare multiple investment returns, and using a chart to not only map them but to also display the variances. For this example, I’m going to compare the historical returns of the S&P 500 against the S&P TSX 60.

Step 1: Setting up the table

The first thing to do is to plot the values into a table format, making it easy to compare the differences. Below, I have multiple columns for the year, S&P 500 returns, and the S&P TSX 60 returns.

Table in Excel comparing investment returns.

Step 2: Calculating the differences and starting point values

The goal of this chart is going to be to not just plot the values of these returns but to also show the gap between them. This can be a little tricky since the value scan be both positive and negative. It’s important to determine where the starting point for the column chart needs to be, and where it finishes.

The first calculated column I’m going to create is for the starting point. If the two returns are both negative, then it will take the largest value (i.e. smallest negative number). Otherwise, it will take the smallest positive value. The formula for the first set of values in row 2 looks as follows:

=IF(AND(B2<0,C2<0),MAX(B2:C2),MIN(B2:C2))

Next, it’s necessary to calculate the gap for when there are both positive and negative returns, and when a crossover needs to happen to get to 0. This column, called crossover, will check to see if the returns are both positive or both negative. And if they are, then it will remain 0 since no crossover is needed. Otherwise, it will return the starting value. The formula for this column is as follows:

=IF((B2*C2)>0,0,D2)

By multiplying the values for both returns, it checks to see if there is a mix of positive values. If there is, then the value will be negative. If they aren’t, then it will return a 0 value.

Lastly, there is a column for the final difference field. First, it checks whether there is a value in the crossover field. If there is, it takes the maximum value in column B or C, which will be the other part of the gap to be filled in . If there isn’t a crossover value, then it looks at the starting value. If the starting value is positive, then it takes the largest value and subtracts the positive one. Otherwise, if the starting value is negative, then it takes the lowest value and subtracts the largest. This is what the formula looks like:

=IF(E2<>0,MAX(B2:C2),IF(D2>0,MAX(B2:C2)-MIN(B2:C2),MIN(B2:C2)-MAX(B2:C2)))

And here is the table, with the values calculated:

Table comparing investment returns in Excel.

Step 3: Creating the chart

Now that the data is setup, the next step is to plot the values on a chart. This requires the use of a combination chart. To create it, make sure a cell on the data set is selected, click on the Insert tab and select the button to pop out more Charts. Go to the All Charts tab and select Combo. The S&P 500 and S&P TSX 60 fields, select the option for Line with Markers and for the others, choose Stacked Column.

Initially, the chart is likely going to look incorrect and may include the date field. To fix this, right-click on the chart and click on Select Data. Remove the Year field if it is there. For the other fields, adjust the Horizontal Axis labels to ensure they are reflecting the year:

Modifying the data source for a chart in Excel.

The chart still has a lot to fix in terms of formatting:

Chart in Excel showing a range of values and variances.

For the line charts, right-click on them and select Format Data Series. Since only the data point is necessary, I will go under the fill bucket tab and under the Line category, select No Line.

Next, the the starting value column, format the data series and for the fill bucket, set the Fill option to No Fill. Then, change the fill color for the difference and crossover columns so that they are the same color. I’ll use grey in this example.

To ensure the column charts stack properly, you’ll also want to modify the order of the series. Right-click to select the data, and ensure that Crossover field comes before the Starting field, followed by the Difference field. Here’s how the chart looks at this stage:

Excel chart showing a range of values.

To clean up the chart a bit, I will move the labels to the bottom. This can be done by right-clicking on the years and selecting Format Axis. Under the Labels section, set the Label Position to Low. I’ll also delete the legend labels for the Crossover, Starting, and Difference fields. The last change is to set a chart title. This is what the final result looks like:

Excel chart comparing the returns of the S&P 500 versus the S&P TSX 60.

If you like this post on How to Create a Chart to Show a Range of Differences, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

GoogleSheetsHeatMap

How to Create a Stock Heat Map in Google Sheets

Heat maps can help you easily identify high and low values. You’ll often find them to display stock prices to show which stocks did well, and which ones didn’t. They can also make it easy to see whether it was a good or bad day on the markets when looking at a list of stocks. In this post, I’ll show you how to create a heat map in Google Sheets to do this.

Step 1: Populating your list of stocks

To start with, I’m going to need a list of stocks to track. I’m going to use the top 20 most valuable stocks as of today’s date and put them into a list:

List of the 20 most valuable stocks in Google Sheets.

Step 2: Calculate the percentage change

Next, I’ll need to setup the percentage change. This can be either the percent change from the previous day, or I could calculate how a stock has done over a specific timeframe, such as a 12-month period. In Google Sheets, you can use the GOOGLEFINANACE function to track the percent change from the previous day. Here’s what that formula would look like, assuming I want to calculate this for the ticker symbol in cell A2:

=GOOGLEFINANCE(A2,”changepct”)

This will return a value to display the percent change.

I’m going to use a more complicated example, however, to show how the stock has performed over the past year. First, I’ll pull in the current stock price, using the following formula:

=GOOGLEFINANCE(A2,”price”)

The trickier part is to pull in the price from a year ago. To go back 365 days, I can set the start date equal to today’s date minus 365 days:

=GOOGLEFINANCE(A2,”price”,TODAY()-365)

The problem is that this returns a table, occupying two rows and columns:

Apple's stock price a year ago.

To ensure I’m just pulling in the closing price, I’ll use the INDEX function to grab the value from the second row and second column:

=INDEX(GOOGLEFINANCE(A2,”price”,TODAY()-365),2,2)

Now, to calculate the percent change, I will take the current price and divide it by the historical price:

=GOOGLEFINANCE(A2,”price”)/INDEX(GOOGLEFINANCE(A2,”price”,TODAY()-365),2,2)-1

I add the -1 at the end to get just the percent change. Now, if I format my values in percentages, I can see how the stocks have performed over the past 12 months:

Google sheets chart showing stock performance.

Step 3: Ranking the values

Using the RANK function in Google Sheets, I can easily determine which stocks were the best and worst performers in the range. The following formula just takes the percentage value in column B and compares it against all the values in that column:

=RANK(B2,B:B)

By copying this formula down, I can now see a ranking of all the values:

Google sheets showing stock performance and ranking.

Step 4: Populate the stocks in order of their performances

Now that the data is setup, I can start arranging the values in order of largest to smallest. To do this, I’m going to use the INDEX function along with the MATCH function to extract the stocks based on their performances. Here is what the first formula will be:

=INDEX($A:$A,MATCH(COLUMN(A1),$C:$C,FALSE),1)

I use the COLUMN function because what I am going to do is drag this formula to the right, so that my largest values go from left to right. And as I copy the formula, A1 will become B1, then C1, and so on. The purpose of this is to increment the function to get the next value. Here is what my table looks like for the first five values:

Top-performing stocks listed in Google Sheets.

These were the five best-performing stocks that were in my list. Below these values, I’m going to also pull in the percentages. This is accomplished through the following formula:

=INDEX($B:$B,MATCH(COLUMN(A1),$C:$C,FALSE),1)

Now I have a list of the top ticker symbols and their percentage gains:

Top-performing stocks listed in Google Sheets along with their changes in value from a year ago.

Step 5: Creating conditional formatting rules

I have the values setup and next I’ll need to create conditional formatting rules to display different colors based on their relative performances. I’ll use a bright green for the best performance, and gradually show a white color when the values are close to zero, and red when they are negative.

I’m going to setup a table which shows the different thresholds I want to track, so it’s easy to change these conditional formatting rules right on the spreadsheet:

Table of conditional formatting thresholds in Google Sheets.

This is my table of values in column K. To setup the rules, I’m going to select the ticker symbols which I ranked in step 4, and create the following conditional formatting rule to start with:

Setting up a conditional formatting rule in Google Sheets.

I’m going to repeat these steps for the values in K2, K3, K4, and K5. I’ll adjust the colors to differentiate between the colors ranges I specified earlier. I use the same formula but simply adjust the cell I’m comparing to:

One thing to note here is that the value I’m using as my comparison is in row two, which is where my percentages are. This means for the conditional formatting rules in the first row, Google Sheets is looking the row below, which contains the percentages.

I’ll need to create another set of conditional formatting rules for the actual percentages themselves in row two. In order to avoid disrupting the formulas and the logic for the first row, I’ll need to create these rules from scratch again. It’s important not to just copy the formatting rules as Google Sheets will end up misinterpreting what I want it to do.

After selecting the values in E2:I2, I create the same conditional formatting rules. The one key difference is that this time I’m referencing the values in row two, not the row below. Once that’s setup, you should now see the same conditional formatting rules applied to both rows:

Heat map conditional formatting rules setup in Google Sheets for multiple stocks.

Step 6: Create borders and setup additional formatting

Before I copy over the formulas and conditional formatting to more rows, I’m going to setup additional formatting and borders. I’m going to make the ticker font larger and bold. And I’ll also outline a border for each stock and its percent change. Here’s what my tickers look like after making these changes:

Heat map conditional formatting rules setup in Google Sheets for multiple stocks.

Step 7: Copying the formatting rules and formulas to accommodate more stocks

I created a row of top 5 stocks but I’m going to expand this so that I have four rows of five stocks each, so that I’m capturing all 20 stocks in my list. To do this, I’m going to copy the cells in E1:I2 multiple times:

Heat map conditional formatting rules setup in Google Sheets for 20 stocks.

I’ve copied the formulas but I need to adjust them so that they aren’t all starting from the top-ranking stock all over again. Here’s how I’m going to adjust this. For the formulas in cells E3:E4, I’m going to add five so that they start at the sixth value. This is the updated formula in E3:

=INDEX($A:$A,MATCH(COLUMN(A3)+5,$C:$C,FALSE),1)

Now I’m going to do the same thing for cell E4. Once I’m done, I’ll copy the formulas across and now my second row is updated to show the stocks in the 6th, 7th, 8th, 9th, and 10th positions:

Heat map conditional formatting rules setup in Google Sheets for 10 stocks.

For the next row, I’ll add 10 to the formulas in column E. Then copy those across. Repeat the same process for the next set of rows and add 15, and do the same. Here’s what my updated table looks like:

Heat map conditional formatting rules setup in Google Sheets for 20 stocks.

Now my heat map is setup to show the percent changes. But as you can see, there’s not a lot of variability here. I’m going to change my values in column K as follows: 100%, 60%, 30%, 20%, -100%. I always leave the last one to -100% to ensure it captures everything else. With the updated rules, now my heat map looks as follows:

Heat map conditional formatting rules setup in Google Sheets for 20 stocks, showing red highlights for the poorest-performing stocks.

Although the values in red are not negative, based on the rules I’ve set out, it highlights the lowest-performing stocks in this list as red, and thus, the sheet follows the rules correctly. You can expand this to include more stocks or to track daily changes or other values.


If you like this post on How to Create a Stock Heat Map in Google Sheets, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

TaskCalendarTemplate

Free Calendar and Task Manager Template

It’s a new year and with the help of a good calendar, you can ensure you stay on top of not only your deadlines and tasks but goals as well. I have a free template which you can download and use for such purposes. With just a few clicks, you can populate a new month, select a custom image, and also have key dates and deadlines appear. And all this is available in a format which is easy to print out.

How the calendar template works

The calendar will populate the days of the month you specify, including the days before and after the end (these dates will be highlighted in grey). You can change the picture for the month and adjust its size depending on how big or small you want it to be. To do this, you can just right-click on the picture and select Change Picture. I’ve also left an area off to the left as blank, giving you room to make any notes.

Default calendar layout.

If you want to change the month, year, or the day that the week starts (either Monday or Sunday), go to the Inputs tab where you can modify those settings.

Inputs to determine the settings for the calendar template.

This is also the tab where you can enter any tasks or deadlines you want to track. They don’t have to be for the current month. Suppose, for example, you have a property tax bill that’s due in July. You can put that task there along with any others you want to track:

Important dates tracked in the calendar template.

These dates will show on the calendar depending on the month selected. If January 2025 is selected, then only dates related to that month will appear.

Dates and deadlines showing for January 2025.

The advantage with this template is that you can enter all your tasks and deadlines for the year and they will show only for the month you specify. This can make it easier to stay on top of tasks without having to remember to enter them all in for that specific month; you can enter them ahead of time and setup recurring ones as well. There is room to accommodate up to five tasks/deadlines for each day.

You can download the free template from here.


If you like this Free Calendar and Task Manager Template, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

FillinPatterns

How to Autofill in Excel: A Step-by-Step Guide

Autofill is one of Excel’s most powerful tools, helping you quickly and efficiently populate cells with data, formulas, or patterns. Whether you’re entering dates, numbers, or repetitive text, learning how to autofill in Excel will save you time and reduce errors.

In this article, I’ll walk through the basics of using Excel’s autofill feature, along with practical examples to help you master this essential tool.

What Is Autofill in Excel?

Autofill allows you to copy or extend data in Excel by dragging the fill handle (a small square in the bottom-right corner of a cell). Excel automatically identifies patterns and fills adjacent cells with the desired data, saving you from manually entering information.

How to Autofill in Excel: Step-by-Step

1. Basic Autofill for Numbers and Text

  • Step 1: Enter a value in a cell.
  • Step 2: Select the cell. You’ll see a small square (the “fill handle”) in the bottom-right corner.
  • Step 3: Hover your mouse over the fill handle until the cursor changes to a black plus sign (+).
  • Step 4: Click and drag the fill handle down or across to the cells you want to fill.
  • Step 5: Release the mouse. Excel will autofill the cells based on the first value.

In the example below, I’m using the autofill to fill in the remaining months of the year.

Using autofill to fill in months of the year.

2. Autofill a Sequence of Numbers

If you want Excel to create a sequence (e.g., 1, 2, 3…), follow these steps:

  • Step 1: Enter the first few numbers in adjacent cells.
  • Step 2: Select multiple cells. The more complex the pattern, the more cells you may need to select.
  • Step 3: Hover over the fill handle, click, and drag it down or across.
  • Step 4: Excel will automatically identify the pattern and fill the cells with the sequence.
Using autofill to continue a sequence in Excel.

3. Autofill for Dates

You can quickly autofill dates to save time.

  • Step 1: Enter a date in a cell (e.g., 01/01/2024).
  • Step 2: Drag the fill handle.
  • Step 3: Excel will autofill with consecutive dates.
Using autofill to fill in dates.

Custom Intervals:
To autofill dates in increments (e.g., every 7 days), follow these steps:

  1. Enter the first two dates (e.g., 01/01/2024 and 01/08/2024).
  2. Select both cells.
  3. Drag the fill handle to extend the sequence.
Autofilling dates in Excel and jumping by one week at a time.

4. Autofill Formulas

Excel can also autofill formulas for quick calculations.

  • Step 1: Enter a formula in a cell (e.g. price x quantity).
  • Step 2: Select the cell with the formula.
  • Step 3: Drag the fill handle down or across to apply the formula to other cells.

Excel will automatically adjust the cell references and fill in the formulas for you. If there is already data which extends as far down as you need to, you can double-click on the fill handle rather than dragging it down, and Excel will automatically go as far down as the rest of the data.

5. Autofill Custom List

If you frequently use custom lists (like days of the week or month names), Excel can autofill these automatically.

For example:

  • Enter Monday in a cell.
  • Drag the fill handle down.
  • Excel will autofill with Tuesday, Wednesday, etc.
Autofilling days of the week in Excel.

Tip: You can create your own custom lists:

  1. Go to File > Options > Advanced.
  2. Scroll down and click Edit Custom Lists.
  3. Add your list, save it, and use autofill as usual.

How to Autofill Without Dragging

If you have a large dataset, dragging the fill handle can be time-consuming. Here’s how to autofill using shortcuts:

  1. Enter the value or formula in the first cell.
  2. Select the range you want to fill (including the starting cell).
  3. Press Ctrl + D to autofill down or Ctrl + R to autofill right.

Common Autofill Issues and Solutions

  • Problem: Autofill copies the same value instead of creating a sequence.
    • Solution: Enter the first two values of the sequence and drag again.
  • Problem: Autofill doesn’t recognize a pattern.
    • Solution: Double-check your entries and use clear patterns like 2, 4, 6 or Monday, Tuesday.
  • Problem: Fill handle is missing.
    • Solution: Go to File > Options > Advanced and ensure the “Enable fill handle” option is checked.

If you like this post on How to Autofill in Excel: A Step-by-Step Guide, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

FixNAErrors

How to Fix #N/A Errors in Excel

Excel is a powerful tool, but even the most experienced users encounter errors like #N/A from time to time. This error can be frustrating, but it’s actually Excel’s way of saying it can’t find the information it’s looking for. Let’s break down why this error happens, and how to fix it.

What does #N/A mean?

The #N/A error occurs when a formula cannot find a value it’s supposed to look up. This commonly happens with lookup functions like VLOOKUP, HLOOKUP, INDEX and MATCH, or XLOOKUP.

Common Reasons for #N/A Errors

When a value isn’t found in your lookup formula, there are multiple possible reasons why that might happen. Here are some of the most common issues:

The value isn’t in the lookup range. The simplest reason is that the value simply isn’t there. Perhaps the value you’re looking for is spelled differently than what you’re searching for, or it just isn’t contained within the data set. An easy way to check for this is to use the CTRL+F shortcut and manually search for the value. If it isn’t found, you’ll get a message saying the value isn’t found. If it is, then it’s likely one of the other reasons that’s causing the error.

An error stating that a value isn't found within a range.

In the above error, ‘Microsoft Corporation’ isn’t found because the text in the range is just ‘Microsoft Corp’

The range or table being searched is incorrect. In this situation, your value exists but it can be that you’re looking in the wrong place. For example, if your data set is in columns A:B but you’re looking at values in C:D, then the value won’t be found. The only way to catch this is to manually look at your formula. By clicking into the formula, it will highlight the range it’s looking at. If it doesn’t look like you’ve selected the right area, that can explain why you are encountering an error.

A VLOOKUP formula which is searching in the incorrect range.

The data types are not the same. In this situation, you may be searching for a numerical value of 1 but the actual value is a text value of 1. This can be a more challenging issue to uncover. However, by using the CTRL+F function you can confirm if the value is indeed found. And if it is found, what you can do is use a formula to check if the values are an exact match. Suppose your lookup value is in cell A1 and the matching value is in cell D100. You can enter the following formula below, to confirm whether it is an exact match:

=A1=D100

If there is an error, that means the data is not the same. At this stage, you may want to do a closer analysis of the values to see if there are any extra characters. You may also want to use the ISNUMBER function to check whether one value is reading as a number and the other as text, as that could be resulting in the #N/A error as well.

The ISNUMBER function in Excel.

If the result of the ISNUMBER formula is FALSE, that tells us that the value is not a number despite it appearing to be.

There are trailing spaces. If your data type is the same and it looks like everything should be matching, then it may be an issue that you have a trailing space, either in your lookup value or the value which it should be matching to. An easy way to check for trailing spaces is by using the RIGHT function. If you don’t specify the number of characters you want to extract from the right, it will by default grab the last one. Then, if you see the formula returning characters, you know there are no trailing spaces. If, however, there is a blank value, this would be confirmation that a blank space exists at the end, and it could be interfering with your lookup.

Checking the last character in a range of cells.

In the above example, column C shows the last character. While there are letters and punctuation, there are no blank values shown.

How to use formulas to suppress #N/A errors

If all else fails and you can’t find the reason for the #N/A error, or it’s not possible to eliminate it without drastically changing your spreadsheet, or you simply don’t have the time to look through all the possible reasons, then you can use formulas to suppress the errors for the sake of eliminating them. There are two options here.

IFNA

The IFNA function can replace the error value with a different value of your choosing. You may want to simply have an empty value, perhaps a 0, or just a different message altogether. In the following formula, I’m using the IFNA function to return a text value of “Not Found” if the value in F4 is not found within column A:

=IFNA(VLOOKUP(F4,A:B,2,FALSE),”Not Found”)

If you encounter any other error, then you’ll still see an error. This function will only suppress #N/A errors.

IFERROR

The IFERROR function works similarly to the IFNA function but the key difference is it will suppress any and all errors. You can deploy it in the same way as you would the formula above:

=IFERROR(VLOOKUP(F4,A:B,2,FALSE),”Not Found”)

The advantage of using this function is it will remove any errors. But that can also be a drawback because if there are different issue causing the error, it won’t be evident, and that can mask other problems within the spreadsheet.


If you like this post on How to Fix #N/A Errors in Excel, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

H2EPivotTableRunningTotals

How to Calculate Running Totals in a Pivot Table

Pivot tables in Excel are useful for summarizing data. But you can do more than just simple summations and can also calculate running totals based on multiple fields. In the spreadsheet which I’ll use for this example, I have sale by month and by category.

Sales values in Excel, broken down by month and category.

Creating and setting up the pivot table

The first step is to create the pivot table. This can be done by just clicking anywhere on the data set and going to the Insert tab and clicking on Pivot Table. I’ll put the dates in the Row section and the sales field in the Values section. I’ll insert the sales field a second time so that I can have one value for the raw monthly sales alongside the running total. Here’s what it looks like thus far:

Pivot table showing sales by month with multiple value fields.

To create a running total, I’m going to right-click on the second sales column and select Value Field Settings. Next, in the Show Values As tab I’ll select Running Total In and use Month as my base field. I’ll also rename the field to say Running Total:

Creating a running total field in a pivot table in Excel.

This sets up the pivot table to show my total sales alongside the running total. A good way to check to see that it is correct is to see that your grand total in the original sales field matches the last value in the running total:

Two sales fields in a pivot table showing the sales total and the running total.

You can also have running totals reset based on the category. In my data, I have electronics and furniture sales. To break it down by those sections, I’ll add the Category field above the Month field in the Rows section. Now I have the running totals broken out by category while still tracking year-to-date values.

A pivot table showing running totals broken out by month and category.

This format may be a bit confusing since the subtotals are above the data. What you may want to do is move the subtotals to the bottom of each section, so that it’s easier to compare them against the running totals to make sure they match up. To do this, click on the pivot table to activate the Design tab. Within there, there is a drop-down option for Subtotals where you can select to Show all Subtotals at Bottom of Group.

The subtotals menu options on a pivot table.

Upon selecting that option, the totals will now appear at the bottom.

A pivot table with subtotals at the bottom of a section.

If you like this post on How to Calculate Running Totals in a Pivot Table, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

TTMCalculation

Calculate Trailing 12 Month (TTM) Values in Excel

Calculating trailing-12 month values, also known as TTM, can be a powerful way to analyze financial or business data over the most recent year. This method focuses on the latest 12-month period, providing a rolling snapshot of performance or trends. Unlike calendar-based analysis, which adheres strictly to yearly or quarterly periods, TTM values are dynamic and update with each new data point. This makes them ideal for ongoing monitoring, where understanding recent trends is more relevant than sticking to predefined reporting periods.

The concept of a TTM value is straightforward: it involves summing, averaging, or otherwise aggregating data from the most recent 12 months. For instance, if you’re tracking monthly revenue, a TTM sum would include the total revenue for the latest 12 months, updating automatically as new months’ data becomes available. This ensures that you’re always working with the most current information, offering a more flexible and actionable view of performance.

Why Are 12-Month Trailing Values Useful?

Calculating TTM values is valuable in contexts where trends or seasonality play a significant role. For example, retail businesses may experience seasonal spikes during the holiday season, while other industries might have cyclical patterns tied to the economy. A TTM analysis smooths out these seasonal fluctuations, offering a clearer picture of overall performance without being skewed by short-term anomalies.

For investors, financial analysts, and business owners, this calculation can be a crucial metric. It helps in understanding key financial ratios (including price-to-earnings ratios), by providing a consistent timeframe for comparison. It also allows for benchmarking against competitors or industry averages, as trailing metrics are widely used in reporting and valuation. Moreover, it can aid in spotting trends early, such as declining sales or increasing costs, enabling proactive decision-making.

Calculating TTM Values in Excel

In the following example, I have sales data by quarter. Since they are quarters, I only need to pull the last four values to get the last 12 months worth of values.

Revenue by quarter.

In the simplest approach, you can just use the SUM function and grab the last four values from the top:

Using the SUM function in Excel to calculate trailing-12 month sales values.

By not freezing any cells and copying the formula down, it will automatically adjust so that it’s always getting the most recent four values.

You can make the formula more dynamic by using the OFFSET function. You can change the number of values you want to add up. And it can be useful if your data is at the bottom, and you want to start from the last value you input. Here’s how you can use a variable to determine how many trailing values you want to calculate.

Using a variable along with the OFFSET function to calculate TTM values in Excel.

Using the OFFSET function, you can specify the height and width of the range. In the above example, I’m using cell F1 to specify the number of periods I want to sum up.

If your most recent values are at the bottom of your range, the OFFSET function can help you with this as well. Here’s how the formula would look like:

=SUM(OFFSET(B2,COUNTA(B:B)-2,0,-4,1))

B2 is the starting reference point.

The COUNTA function counts the number of nonblank cells in column B. It is reduced by 2 since the reference point, B2, is in row 2. It needs to be reduced by 2 to get back to 0.

There are 0 columns to offset, hence the next argument is 0.

The -4 tells the formula that you want to go back 4 rows.

The 1 at the end tells the formula that it is just 1 column wide.

This produces an array, which is then summed up through the SUM function.


If you like this post on How to Calculate Trailing 12 Month (TTM) Values in Excel, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

StockHighandLow2

Add Horizontal Lines to Stock Charts to Identify Min and Max Values in Excel and Google Sheets

If you’re pulling in stock prices into your spreadsheet, you can easily plot those values on a chart. And one way to help visualize the data is to add horizontal lines to help you identify where the maximum and minimum values are. I’ll go over how this can be done in both Excel and Google Sheets.

Pulling in the historical stock prices in Excel and Google Sheets

In Excel, you can use the STOCKHISTORY function to pull in historical stock prices. And in Google Sheets, there’s the GOOGLEFINANCE function. Both are fairly straightforward functions which can extract stock prices going back days, months, and even years.

Below, I’ve pulled Nvidia’s stock price history from Jan 1, 2024 through to Oct 31, 2024, in Excel:

NVDA stock price history in Excel.

And here is the price history in Google Sheets:

NVDA stock price history in Google Sheets.

Calculating the highs and lows

In Google Sheets, you can pull in a stock’s 52-week high and low from right within the GOOGLEFINANCE function. But in this example, I’m going to calculate the minimum and maximum values based on the range that has been downloaded. This will make the chart more dynamic, allowing you to have these values updated based on your range.

In both Excel and Google Sheets, I’ll setup columns for HIGH and LOW. I’ll use the MAX function to get the highest value and the MIN function to get the lowest value. The only argument needed is the column which contains the closing price. The same value needs to be repeated in both of these columns to ensure the line is horizontal.

The formula is exactly the same whether you’re using Excel or Google Sheets. What’s important, however, is to ensure the values are the same all the way down; you’ll want to copy it all the way to the bottom. Here’s how it looks in Excel:

NVDA stock price history in Excel showing highs and lows for a period.

Plotting the values on a chart

Next, with the highs and lows added, it’s just a matter of creating a line chart which shows these values. The default formatting in Excel already does this effectively for me, displaying the high and low ranges:

High and low values plotted on a chart in Excel.

At this stage, it’s just a matter of any additional formatting you may wish to do, such as changing the line colors. I also prefer to make these dotted lines, and this can be done by changing the dash type. Here’s what my finished chart looks like in Excel:

Excel stock chart showing maximum and minimum values.

To format the individual lines, right-click to Format Data Series, where you can then change the color and the dash type. The changes I made above are to change the color to black and the lines to a dash. I have also added vertical gridlines to the chart by going to the Chart Design tab and selecting Add Chart Element and Gridlines and then clicking Primary Major Vertical.

On Google Sheets, the process is largely the same. The main difference is that you need to access the edit chart menu and under the Customize tab, select your options for gridlines, color, and dash type for an individual data series.

Google Sheets stock chart showing maximum and minimum values.


If you like this post on Add Horizontal Lines to Stock Charts to Identify Min and Max Values in Excel and Google Sheets, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

DynamicCalendar2

Dynamic Calendar Template and Organizer for Excel

Do you want to track deadlines and have an easy place to manage all your upcoming tasks and bills? In this post, I’m going to share with you my Dynamic Calendar Template. This template will allow you to input dates and create conditional formatting rules so that it’s easy to see important items on your calendar. You can also see up to five items per day and switching between different months and years, so you’ll only see items for that specific month.

How the Dynamic Calendar Template works

Everything is conveniently available in a single tab and there are no macros in this file. The calendar is on the left-hand side of the page while the events and important dates you input are on the right.

Dynamic calendar template in Excel.

Today’s day will automatically highlight in yellow. To add events, all you need to do is input a date, a description for the event, and you can also specify a flag (conditional formatting rule) that you want to apply to that item. In the example below, I’ve setup events for Nov. 28 and Nov. 29.

Dynamic calendar template with multiple events entered in.

Since I’ve set flags for the specific events, they are highlighted accordingly in my calendar. You don’t need to specify a color, but it is not necessary to do so.

You can also change the dates for the calendar by adjusting the month and year options in-between the calendar and the events table. If the events don’t relate to a specific month, they won’t appear on your calendar. This way, you can add many events far into the future and they won’t appear on your calendar until you are viewing that specific month and year.

You can download the free template available here.

Use the premium version for multiple calendars and recurring events

There is also a premium version available for this template which will allow you to use macros to generate recurring events. And you can also add multiple calendars. If you want to balance personal, work, family, and other types of calendars, you’ll be able to do that with this template. On the main calendar tab, there is an additional drop-down option where you can specify which calendar you want to use, in addition to setting the month and year.

Dynamic calendar template with multiple calendars to choose from.

On this template, there is a separate sheet for inputs, where you can add to the list of calendars and when entering events, you can include which calendar you want to use. To setup recurring events, I can create the events that I want to setup and specify how many events I want to generate in advance. And upon clicking the macro button, it will add them to the events table.

The recurring events section of the Dynamic Calendar template.

After clicking Generate Recurring Events, the events table is now populated with events for the next 12 occurrences. Since, in this case, they occur every 12 months, it will add the annual occurrence for the next 12 years.

Setting up recurring events in the Dynamic Calendar template.

Once the events are created, the value for the # of events to generate resets back to 0. The macro will only create instances when this value is filled in, the avoid creating extra events.

The recurring events section of the Dynamic Calendar template with events to generate set to zero.

You can, however, remove any events by just right-clicking on the events listed and selecting Delete Table Rows.

Deleting events from the Dynamic Calendar template.

Now, when going back to the calendar and adjusting the date to July 2025, the first even will appear.

The Dynamic Calendar template showing for July 2025.

If you are interested in purchasing the premium version, please visit the product page here.


If you like this Dynamic Calendar Template, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.

sddefault (2)

How to Import Tables From Wikipedia Into Excel

You can import a lot of different data into your Excel spreadsheet. In this post, I’ll show you how you can get tables from Wikipedia both manually and with the help of Power Query. For this example, I’m going to use the page for the largest fast food restaurant chains. The data is sorted in a table, making it ideal to import into Excel.

How to import a Wikipedia table into Excel by copying and pasting

1. Copy and paste the values. Since the data is easily organized in Wikipedia, you can just use your mouse to drag, and copy and paste everything into Excel. The hardest part is just to make sure you’ve selected everything you want to copy.

Here is how the data looks after you’ve removed formatting:

Wikipedia table showing fast food restaurants and the number of locations.

Pro tip: if you have the latest version of Excel, you can use CTRL+SHIFT+V to copy the values without any additional formatting.

2. Remove the comments and values in brackets. In Wikipedia tables, you’ll often see references and notes after values. To remove this, you can use find and replace in Excel to get rid of the values. Set it up so that you replace [*] with nothing. The asterisk will remove everything which comes between the brackets, as well as the brackets themselves.

Replacing values in brackets with blanks.

You can repeat these steps if there are any values in parentheses ( ) as well and any other special characters. After these steps, your data should look much cleaner. The downside is that it may take multiple adjustments to get the data cleaned up correctly and for all the issues to be accounted for.

Wikipedia table showing fast food restaurants with data cleaned up.

Import Wikipedia tables using Power Query

Another way you can import tables is with the help of Power Query. Here’s how you can do that:

1. In the Data tab, select From Web and copy the link and press OK.

Using Power Query to import a web page.

2. Select the table which resembles the data you want to import. Oftentimes there can be multiple tables, so it can be a good idea to cycle through them to see which one is the best match for your data. Then hit the button to Transform Data.

Selecting the table to import in Power Query.

3. Remove any unneeded columns. To remove columns in Power Query, right-click on the headers and select Remove.

Removing columns in Power Query.

4. Clean up the data. You can use the Extract option in Power Query to grab values that come before a specific character. This is similar to the find and replace function but it can remove everything before a value:

Using the Extract function in Power Query.

Here you can specify the opening parenthesis as the character. You can repeat this step for brackets and other characters as well. This type of find and replace can also be done within Excel by just using *( to grab everything before the opening of a parentheses or *[ before an opening bracket.

Using text before delimiter in Power Query to pull values before a specified text.

Then, convert the values to Whole Number to ensure they are formatted correctly. If they aren’t, you’ll see some error values, in which case you’ll have to go back to the previous step to correct them. Otherwise, you are done and ready to move on to the last step.

5. Load the data back into your Excel spreadsheet. For this step, all you need to do is click on Close & Load on the Home tab.

The Close and Load button in Power Query.

Your formatted table is now loaded into Excel:

A Wikipedia table downloaded and formatted into Excel using Power Query.

The benefit of using Power Query is that it saves your steps just like a macro would. If you want to refresh the data and download it again, to check for updated information, you can just right-click on the table and select Refresh.


If you like this post on How to Import Tables From Wikipedia Into Excel, please give this site a like on Facebook and also be sure to check out some of the many templates that we have available for download. You can also follow me on Twitter and YouTube. Also, please consider buying me a coffee if you find my website helpful and would like to support it.