Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Running Total Removing Blanks

Hi Everyone, could use some help.

I have a DAX caluclation issue in Power BI. I have a date and sales table joined via a one-to-many relationship on the 'date' column.

 

I want to calulate a running total that resets every month up until the latest sales date.

 

I have a current calculation that works but it shows blank values where there is no sales[salesdate] that equals a date[date] (generally weekends). The current calculation does end on the latest sales date, however I just want these blank values to display the last value if possible.

The calculations and table I am using:

Simple Sales Measure:

Sales = SUM(Sales[Sales])

 

Current Running Total Measure:

VAR _LastSalesDate = MAX(Sales[SalesDate])
Return
IF(
SELECTEDVALUE('Date'[Date]) <= _LastSalesDate,
CALCULATE([Sales],
DATESMTD(('Date'[Date]))))
 
Anony51_0-1651697589353.png

 

Any help would be appreacited, this problem has recently become the bane of my existence. 

 

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

To your visual, ensure that you drag the Date column from the Date table.  Write this measure:

Current Running Total Measure =calculate([Sales],datesmtd(calendar[date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi,

 

Thanks alot for your help. This fills in the blanks that I was getting before and computes a new total starting every month. 

I've added the date column from the date table and the calculation you posted but how do I get it to stop showing any values or show blanks past the sales date. The last sales date is the 04/05. 

Anony51_0-1651709838109.png

Thanks

 

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

For context, what I am tring to do is create the table to stop dsplaying the running total after the last sales date and have the line graph to stop displaying after the last sales date as it plateaus and becomes flat. 

 

The requirement is that there must be a line graph that is categorical, with a running total that stops after the last sales date. And a slicer that can select different months where the running total should reset every month. I completed this using my measure (Running Total Measure) but it shows blanks and gaps in previous months where there is no sales on a date.

Anony51_0-1651744436458.png

 

Using your measure worked but then it it keeps running until the end of the month and becomes flat. 

Anony51_1-1651744540802.png

 

Ideally I need a combination of the two, a running total that has no blanks for any date and it should stop running after the last sales date. 

 

Any help would be appreciated.

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi,

 

It looks like it's worked. For my own benefit, could you explain why you did this calculation and the logic that is occuring in it.

Date till which actual sales are available = 
CALCULATE(MAX(Sales[SalesDate]),FILTER(ALL('Date'[Date]),[Sales1]>0))

Sales1 = SUM(Sales[Sales])

And why does this not work in this scenario, why do you have to filter it by date and sales? 
MAX(Sales[SalesDate])

 

The following calculation you provided for running total:

Running Total Measure = 
IF(MAX('Date'[Date])>[Date till which actual sales are available], blank(),
calculate([Sales1],datesmtd('Date'[Date])))

For this calculation, just wondering why you used MAX('Date'[Date]), wouldn't this just apply for the maximum date in the date table (i.e. 30 March 2022) being blank and not every date after the sales date.

 

Or am I misinterpreting the logic. Any explanation on all of this would help me going forward.

 

Thanks.

The first calculation is to determine the last date till which there is data in the actual sales table.  Via this measure, I have applied a filter on where sales > 0 and then calculated the max date from the actual sales table.  Max(Date[Date]) will return the date of the existing row in the matrix visual.  So if the date in the matrix visual is > [Date till which actual sales are available] then show a blank, else perform the MTD calculation.

If my previous reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.