Summary of Thread:
In this scenario, we want to calculate the average monthly cost by category in the current year. We want to prep the data easily without needing a lot of formulas. We’ll use Pivot Tables to prep the data and write an Average formula against the results.
There is a how-to guide that Tiller put together on pivot tables (thanks @Clint.C for providing that!) For this example, we’re using Google Sheets:
Visualize Your Financial Data With a Pivot Table
To make the Transactions sheet more useful for pivot tables, be sure it includes columns with values for Year and Group.
From the Transactions sheet, select the entire table or click on any cell in the table with data, then choose Insert > Pivot Table > New Sheet. Make the following selections in the pivot table editor (in this example, Year is filtered to 2024).
We end up with the sum of amounts by category for each month in 2024. Note that we only have through August so far, and August will be a partial month. Also, by default, each row and column checks the “Show totals” box, which creates totals that we don’t want for prepping data to calculate averages.
So: let’s uncheck the “show totals” boxes but leave the current month in the results to be dealt with in @Mark.S 's Monthly Avg formula. Insert a column to the left of A and name it “Monthly Avg.” Our results now look like this:
Paste the following formula beside your first result row, then drag the formula down well past the last row so you have room to grow; those blank rows will just show $0.
=AVERAGE(FILTER(ARRAYFORMULA(IF($C6:$N6="", 0, $C6:$N6)), ($C$5:$N$5 < EOMONTH(TODAY(), -1) + 1), NOT(ISBLANK($C$5:$N$5))))
Here’s the basic breakdown of Mark’s formula:
- Calculate the average of the value defined in the pivot table editor (sum of Amount)
- …by the row value (Category)
- …for each column value (Month)
- …filtered by the Year you selected in the pivot table editor.
- For the current year, the pivot table displays through the current month, but the formula still looks to all 12 columns to accommodate the future months as they appear.
- Since the current month is likely a partial month and would give misleadingly low inputs, the Monthly Avg formula ignores the current month
- Notice in our example that Insurance is paid quarterly and has blank months. The formula treats those as 0 to provide an accurate monthly average.
Note that we chose to still display the month-to-date value for August in the pivot for informational purposes only, so we don’t add a filter to exclude a month that we forget to remove later
Now our sheet looks like this:
…and down to blank rows with $0’s…
@alkrongold would like to add additional Row values to organize and expand/collapse. For example, I added Group to the pivot table editor in the Rows section, optionally checked “show totals” for Category, and we get this:
Somebody good with math will have to tell me if this is at all accurate.
You can make a copy of the sample file Pivot Tables - Sample Data.