Running total is the cumulative total of all the data points in a sequence. For example: If we have sales of three months as $100, $150 and $ 180, so running total will be calculated by adding the data points one by one to the sales amount. The result will be:

100

(100+ 150)= 250

250+180=430

*Why calculate running total?*

Running total is calculated to identify trends and anomalies, monitoring company's sales progress and understanding accumulated figures related to numerical data points. The results of the calculations can then be plotted in a visual.

Now let' see how we can apply this concept in Postgres and Power BI.

Here, I have created a table sales:

And inserted some values:

The table looks like this:

For calculating running total in Postgres, we have to identify on which column we need running total to sum up the values for a set of rows one by one and order by date column. So, the formula will be:

Let's see how we can calculate running total by using Common Table Expression in Postgres.

Now, we will look at how to calculate running total in Power BI with the same dataset.

Here, we have to use the DAX formula to achieve the goal. We will calculate the running total with date this time.

In this formula, we are summing up the sales amount and filtering the result when the current date is les than max sales date, so the result will be cumulative value row by row. Let's plot the result as a line chart:

Here we can see the line chart is going down by default as dates are not sorted in the dataset. After sorting the Dates by ascending order and selecting the area chart, we get the below graph:

Running totals are calculated in the companies for looking at trends and patterns at a specific time. We can easily see the total at one particular time (eg: year, month, quarter) without summing the whole sales.

Thanks for reading!