5 Ways To Calculate Running Total In Excel Power Query

Intro

Master running totals in Excel Power Query with ease. Learn 5 efficient ways to calculate cumulative sums, including using Group By, Index Columns, and Variables. Boost your data analysis skills and simplify complex calculations with these expert-approved methods and related Power Query formulas.

Excel Power Query is a powerful tool that allows users to easily manipulate and analyze data. One common task that users often need to perform is calculating a running total, which can be useful in a variety of scenarios, such as tracking inventory levels, calculating cumulative sales, or monitoring progress towards a goal.

In this article, we will explore five different ways to calculate a running total in Excel Power Query. Whether you are a seasoned Power Query user or just starting out, these methods will help you to easily calculate running totals and take your data analysis to the next level.

Method 1: Using the Running Total Function

Running Total Function in Power Query

One of the easiest ways to calculate a running total in Power Query is by using the built-in Running Total function. This function allows you to calculate a running total of a column based on a specified grouping.

To use the Running Total function, follow these steps:

  • Go to the "Add Column" tab in the Power Query editor
  • Click on "Custom Column"
  • In the formula bar, type =Running.Total([Your Column Name], "Your Grouping Column")
  • Replace [Your Column Name] with the name of the column you want to calculate the running total for, and "Your Grouping Column" with the name of the column you want to group by

For example, if you have a table with columns for Date, Sales, and Region, you can use the Running Total function to calculate the cumulative sales by region.

Example:

Date Sales Region
2022-01-01 100 North
2022-01-02 200 North
2022-01-03 300 South
2022-01-04 400 South

Running Total: =Running.Total([Sales], "Region")

Result:

Date Sales Region Running Total
2022-01-01 100 North 100
2022-01-02 200 North 300
2022-01-03 300 South 300
2022-01-04 400 South 700

Method 2: Using the Index Column

Index Column in Power Query

Another way to calculate a running total in Power Query is by using the Index column. This method involves creating an Index column, then using the SUM function to calculate the cumulative total.

To use the Index column method, follow these steps:

  • Go to the "Add Column" tab in the Power Query editor
  • Click on "Index Column"
  • In the formula bar, type =SUM([Your Column Name]{0..[Index]})
  • Replace [Your Column Name] with the name of the column you want to calculate the running total for

For example, if you have a table with columns for Date and Sales, you can use the Index column method to calculate the cumulative sales.

Example:

Date Sales
2022-01-01 100
2022-01-02 200
2022-01-03 300
2022-01-04 400

Index Column: =SUM([Sales]{0..[Index]})

Result:

Date Sales Running Total
2022-01-01 100 100
2022-01-02 200 300
2022-01-03 300 600
2022-01-04 400 1000

Method 3: Using the Group By Function

Group By Function in Power Query

You can also calculate a running total in Power Query by using the Group By function. This method involves grouping the data by a specific column, then calculating the cumulative total for each group.

To use the Group By function, follow these steps:

  • Go to the "Home" tab in the Power Query editor
  • Click on "Group By"
  • In the formula bar, type =Group.By([Your Grouping Column], "Sum", [Your Column Name])
  • Replace [Your Grouping Column] with the name of the column you want to group by, and [Your Column Name] with the name of the column you want to calculate the running total for

For example, if you have a table with columns for Date, Sales, and Region, you can use the Group By function to calculate the cumulative sales by region.

Example:

Date Sales Region
2022-01-01 100 North
2022-01-02 200 North
2022-01-03 300 South
2022-01-04 400 South

Group By: =Group.By([Region], "Sum", [Sales])

Result:

Region Running Total
North 300
South 700

Method 4: Using the Power Query M Language

Power Query M Language

You can also calculate a running total in Power Query using the Power Query M language. This method involves writing a custom M language formula to calculate the cumulative total.

To use the Power Query M language, follow these steps:

  • Go to the "Advanced Editor" tab in the Power Query editor
  • Write a custom M language formula, such as =Table.Scan([Your Table], each List.Sum([Your Column Name]{0.._})
  • Replace [Your Table] with the name of the table you want to calculate the running total for, and [Your Column Name] with the name of the column you want to calculate the running total for

For example, if you have a table with columns for Date and Sales, you can use the Power Query M language to calculate the cumulative sales.

Example:

Date Sales
2022-01-01 100
2022-01-02 200
2022-01-03 300
2022-01-04 400

Power Query M Language: =Table.Scan([Your Table], each List.Sum([Sales]{0.._})

Result:

Date Sales Running Total
2022-01-01 100 100
2022-01-02 200 300
2022-01-03 300 600
2022-01-04 400 1000

Method 5: Using the DAX Formula

DAX Formula

Finally, you can also calculate a running total in Power Query using a DAX formula. This method involves creating a new measure using the DAX formula language.

To use a DAX formula, follow these steps:

  • Go to the "Modeling" tab in the Power Query editor
  • Click on "New Measure"
  • In the formula bar, type =CALCULATE(SUM([Your Column Name]), FILTER(ALL([Your Table]), [Your Column Name] <= EARLIER([Your Column Name])))
  • Replace [Your Column Name] with the name of the column you want to calculate the running total for, and [Your Table] with the name of the table you want to calculate the running total for

For example, if you have a table with columns for Date and Sales, you can use a DAX formula to calculate the cumulative sales.

Example:

Date Sales
2022-01-01 100
2022-01-02 200
2022-01-03 300
2022-01-04 400

DAX Formula: =CALCULATE(SUM([Sales]), FILTER(ALL([Your Table]), [Sales] <= EARLIER([Sales])))

Result:

Date Sales Running Total
2022-01-01 100 100
2022-01-02 200 300
2022-01-03 300 600
2022-01-04 400 1000

We hope this article has helped you to learn how to calculate running totals in Power Query using different methods. Whether you are a beginner or an advanced user, these methods will help you to easily calculate running totals and take your data analysis to the next level.

Jonny Richards

Love Minecraft, my world is there. At VALPO, you can save as a template and then reuse that template wherever you want.