A local-first personal finance app
improve summary report monthly average calculation (#4302)
Matt Fiddamanc8d14cae0977
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.tsindex 1846b66b6a..68fa418c09 100644--- a/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts+++ b/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts@@ -48,7 +48,10 @@ export function summarySpreadsheet();endDay = d.parse(- monthUtils.lastDayOfMonth(end),+ monthUtils.getMonth(end) ===+ monthUtils.getMonth(monthUtils.currentDay())+ ? monthUtils.currentDay()+ : monthUtils.lastDayOfMonth(end),'yyyy-MM-dd',new Date(),);@@ -196,13 +199,18 @@ function calculatePerMonth(amount: monthlyData[d.format(m, 'yyyy-MM')] || 0,}));+ const lastMonth = months.at(-1)!;+ const dayOfMonth = lastMonth.getDate();+ const daysInMonth = monthUtils.getDay(monthUtils.lastDayOfMonth(lastMonth));+ const numMonths = months.length - 1 + dayOfMonth / daysInMonth;+const totalAmount = monthsSum.reduce((sum, month) => sum + month.amount, 0);- const averageAmountPerMonth = totalAmount / months.length;+ const averageAmountPerMonth = totalAmount / numMonths;return {total: averageAmountPerMonth / 100,dividend: totalAmount / 100,- divisor: months.length,+ divisor: numMonths,};}diff --git a/upcoming-release-notes/4302.md b/upcoming-release-notes/4302.mdnew file mode 100644index 0000000000..5ef11bf8e6--- /dev/null+++ b/upcoming-release-notes/4302.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [matt-fidd]+---++Improve summary report monthly average calculation