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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-jayw-msft
Community Support
Community Support

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

5 REPLIES 5
v-jayw-msft
Community Support
Community Support

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
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

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.