Skip to content

andreabragantini/bank-statement-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

Bank Statement Analyzer (Danske Bank)

This project contains an R script designed specifically for analysing Danske Bank statement exports. The script loads the Excel worksheet provided by the bank, categorises spending using simple regular expressions, and then creates summary charts for monthly spending trends and average expenses per category.

Prerequisites

Install the packages in R with:

install.packages(c("plyr", "ggplot2", "readxl"))

Getting started

  1. Download your Danske Bank transactions as an Excel file (the default name resembles DanskeKonto-<account>-<date>.xlsx) and place it in the project directory.

  2. Open StatementAnalyzerDanskeBank.R and replace the hard-coded Excel filename in the read_excel() call with the name of your export file.

  3. Ensure the worksheet structure matches the script expectations: the columns should be (in order) Date, Text, Amount, Balance, and any additional metadata provided by the bank. If your export differs, adjust the col_types argument passed to read_excel() accordingly.

  4. From an R session (or RStudio), source the script:

    source("StatementAnalyzerDanskeBank.R")

    The script filters out income rows, assigns spending categories, and generates two plots:

    • Monthly totals per category: a faceted scatter and smoothing chart of spending over time.
    • Average monthly expense per category: a bar chart summarising typical outgoings.
  5. Use R's plotting window to inspect or save the generated charts.

Customising categories

The categorisation logic uses regular expressions stored in variables such as cash, food, flights, transport, gas, and rent. Update the regex patterns or add new variables to reflect your own merchants and spending categories, then extend the nested ifelse block to map them to friendly labels.

For more flexible categorisation, consider extracting the mapping into a lookup table (e.g. a CSV file) and applying it with dplyr::case_when() or a join. This keeps the logic declarative and easier to maintain.

Next steps & ideas

  • Add unit tests or sample data to make it easier to verify changes.
  • Parameterise the input file path so the script can be run from the command line without editing the source.
  • Replace the nested ifelse statements with a tidier approach such as dplyr::case_when().
  • Export the visualisations directly to image files (e.g. via ggsave) for sharing or reporting.
  • Package the script as an R function or minimal package to improve reusability.

License

This project currently has no explicit license. Consider adding one to clarify usage rights.

About

General purpose R script for loading raw data from your bank statement, analysis and and visual outputs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages