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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

Reply
Anonymous
Not applicable

Running total too slowly

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)? 
2 REPLIES 2
Anonymous
Not applicable

HI @Anonymous,

Have many records your calendar table stored? Account to your description, It seems like you use the cumulative calculation expression on the calendar table to summary table2 records.
For this scenario, it means each calendar row will be looping with table 2 records. (the total looping row count = calendar row count * [2 * selected calendar row count + table2 row count ] )

In addition, I modify the formula to reduce the calculation row counts, you can also try to use the following formula if helps:

prior to date =
VAR currDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table (2)'[Time ] ),
        FILTER ( ALLSELECTED ( 'Table (2)' ), 'Table (2)'[Date] <= currDate )
    ) + 0

Reference link about Dax iterator performance:

Optimizing nested iterators in DAX - SQLBI

Regards,

Xiaoxin Sheng

amitchandak
Super User
Super User

@Anonymous , I tried like this

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

 

Data is very small, I do not face any performance issue

 

what you showing is not last month till date

 

The file is attached after signature

 

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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