How do I build a correct running total for previous years in Power BI using DAX

0 votes

How do I build a correct running total for previous years in Power BI using DAX?
I need help building a running total for previous years in Power BI using DAX. My current DAX formula isn't correctly aggregating the values for previous years, and I need guidance on how to modify the formula to calculate the running total correctly for historical data.

3 hours ago in Power BI by Evanjalin
• 33,850 points
5 views

1 answer to this question.

0 votes

To build a correct running total for previous years in Power BI using DAX, you need to adjust your DAX formula to consider the historical data for each year and sum it cumulatively. Here's a step-by-step approach to do this:

Steps for Building a Running Total for Previous Years:

  1. Ensure you have a Date Table:

    • Make sure you have a Date Table in your model, and it's related to your fact table. Power BI requires a continuous Date Table for time intelligence functions to work correctly.

    • If you don't have a Date Table, you can create one using this DAX formula:

DateTable = CALENDAR(DATE(2010,1,1), DATE(2030,12,31))

Create a Measure for the Cumulative Total:
To calculate a running total for previous years, you can use the TOTALYTD() or CALCULATE() function with FILTER() to ensure the total includes data for each year cumulatively.

Here’s an example of how to calculate the running total for previous years:

RunningTotalPreviousYears = 
CALCULATE(
   SUM('Sales'[Amount]), 
   FILTER(
      ALL('Date'), 
      'Date'[Date] <= MAX('Date'[Date]) && YEAR('Date'[Date]) < YEAR(TODAY())
   )
)
  1. Visualize the Running Total:

    • Now, create a line chart or table in Power BI and use this RunningTotalPreviousYears measure to display the cumulative sum for the previous years.

Example of a Working Formula for Running Total (Excluding Current Year):

RunningTotalPreviousYears = 
CALCULATE(
    SUM('Sales'[Amount]), 
    FILTER(
        ALL('Date'), 
        'Date'[Date] <= MAX('Date'[Date]) && YEAR('Date'[Date]) < YEAR(TODAY())
    )
)

Important Notes:

  • ALL('Date') is used to ignore any slicers or filters that might restrict the date range in your report.

  • The MAX('Date'[Date]) ensures that the calculation includes data up to the current row's date.

  • The YEAR(TODAY()) condition ensures that the running total does not include data from the current year, only from previous years.

answered 3 hours ago by anonymous
• 33,850 points

Related Questions In Power BI

0 votes
2 answers

How do I optimize DAX queries for better performance in Power BI?

To improve performant DAX queries for the ...READ MORE

answered Nov 19, 2024 in Power BI by Vani
• 3,580 points
448 views
+2 votes
2 answers

How do I implement row-level security (RLS) in Power BI using DAX?

Suppose you are considering sharing your Power ...READ MORE

answered Oct 21, 2024 in Power BI by pooja
• 24,450 points
391 views
0 votes
1 answer

How do I implement custom aggregations in Power BI using DAX?

Utilizing DAX (Data Analysis Expressions) to create ...READ MORE

answered Oct 23, 2024 in Power BI by pooja
• 24,450 points
393 views
0 votes
1 answer

How do I calculate a rolling average or cumulative total in Power BI without performance issues?

To enable rolling averages or cumulating summations ...READ MORE

answered Dec 30, 2024 in Power BI by Anu
• 3,020 points

edited Mar 6 348 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,090 points
1,780 views
+1 vote
1 answer

Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

answered Aug 22, 2018 in Power BI by nirvana
• 3,090 points
3,146 views
+2 votes
2 answers

Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

answered Oct 11, 2018 in Power BI by Hannah
• 18,520 points
1,943 views
+1 vote
1 answer

Connect power bi desktop to dataset and create custom reports

Open power bi report nd sign in ...READ MORE

answered Oct 10, 2023 in Power BI by Monika kale

edited Mar 5 2,142 views
0 votes
1 answer

How do I configure a read-only user for PostgreSQL in Power BI to maintain security?

To configure a read-only user for PostgreSQL ...READ MORE

answered Feb 28 in Power BI by anonymous
• 33,850 points
222 views
+1 vote
1 answer

Why am I unable to set refresh for a web-based anonymous connection in Power BI Server, and how can I resolve it?

Scheduled refresh for web-based data sources that ...READ MORE

answered Feb 28 in Power BI by anonymous
• 33,850 points
292 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP