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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate runnig total till last month between selected dates

Hi,

 

I've a simple model, Iput a pbix file https://1drv.ms/u/s!Amd7BXzYs7AVhBEkwk7KkWhVqete?e=sireeV 

jaweher89_0-1640702274266.png

 

I'm trying to calculate runnig total till last month between two selected dates, as example:

 

Year monthdaytimerunning total( classic) Prior till last month (expected)
201911212120
2019114152712
2019212184527
2019213216645
2019214249066
20195152711790
201951630147117
201951733180147
2019121836216180
202041939255216
202042042297255
202042145342297
202052248390342
202052351441390
202072454495441
202082557552495
202092660612552
2020122763675612

 

jaweher89_0-1640703108019.png

 

I tried, but prior to date is too slowly, how to optimize it? When I do a search on net, may be I need to use RANKX but I don't to figure out how to use it?

 

prior to date = var _maxdate=CALCULATE(max('Date'[Date]), ALLSELECTED(('Date'[Date])))
var _mindate=CALCULATE(min('Date'[Date]), ALLSELECTED(('Date'[Date])))
return
calculate(sum('Table (2)'[Time ]), filter(all('Date'), 'Date'[Date]<=max('Date'[Date])))+0
 
How to calculate Prior till last month (expected)? 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

You have already used the 'Date'[date] in the table, so you could simply use the below formulas.

running total = CALCULATE(SUM('Table (2)'[Time ]),FILTER(ALLSELECTED('Date'[Date]),'Date'[Date]<=MAX('Date'[Date])))

Prior till last month = CALCULATE(SUM('Table (2)'[Time ]),FILTER(ALLSELECTED('Date'[Date]),'Date'[Date]<=EDATE(MAX('Date'[Date]),-1)))

Capture.PNG

 

Best Regards,

Jay

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

 

You have already used the 'Date'[date] in the table, so you could simply use the below formulas.

running total = CALCULATE(SUM('Table (2)'[Time ]),FILTER(ALLSELECTED('Date'[Date]),'Date'[Date]<=MAX('Date'[Date])))

Prior till last month = CALCULATE(SUM('Table (2)'[Time ]),FILTER(ALLSELECTED('Date'[Date]),'Date'[Date]<=EDATE(MAX('Date'[Date]),-1)))

Capture.PNG

 

Best Regards,

Jay

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

calculate(sum('Table (2)'[Time ]), filter(all('Date'), 'Date'[Date]<= eomonth(max('Date'[Date]),-1) ))+0

 

or

 

calculate(sum('Table (2)'[Time ]), filter(allselected('Date'), 'Date'[Date]<= eomonth(max('Date'[Date]),-1) ))+0

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak  It's too much slowly, and I need to use selected periods, I update my question with more details.

@Anonymous , the measure with all selected should do

calculate(sum('Table (2)'[Time ]), filter(allselected('Date'), 'Date'[Date]<= eomonth(max('Date'[Date]),-1) ))

 

You should display it with the month year from the date table.

 

No need of +0 too

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak  I need to disply all dates between two selected dates, so for that I need +0 

I'm looking for a better solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.