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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
193
Frequent Visitor

Ending balance calculation speed up

Hello,

 

I need to calculate ending balance depending on filter selections in the report.  

I found a way to get the desired result but it takes too long...

193_0-1672085352247.png

I add pbx file here: https://1drv.ms/u/s!AjCQWBzIRUrlwVraSjUjhGqOpTri?e=vqDO3G 

 

Any ideas how could I improve my measure?

 

Thanks!

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @193 

You can use the following code:

Measure = CALCULATE([BS],FILTER(ALL(GL),GL[Acc]=MAX(GL[Acc])&&[Index]<=MAX(GL[Index])))

vxinruzhumsft_0-1672105209612.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

ppm1
Solution Sage
Solution Sage

The filter on the high granularity index column is the reason for the slowness. If the running total won't change with slicers, etc., it would be good to pre-calculate it in your query. The new WINDOW function may be a good approach too. However, below is a measure expression that is much faster. Please try it and report back. It calculates the running total from a day standpoint and then just subtracts any index values that came later on same day (if any). Note that I also used the Date column from your Date table in the visual, instead of the one from the GL table.

 

End_bal 2 = 
var thisindex = max(GL[Index])
var maxdate = MAX('Date'[Date])
VAR IndexValues = CALCULATETABLE(DISTINCT(GL[Index]), ALL(GL), VALUES(GL[Acc]), 'Date'[Date] = maxdate)
var FilteredIndexValues = FILTER(IndexValues, GL[Index] > thisindex)
VAR DayRT =
    CALCULATE (
        [BS],
        ALL(gl), VALUES(GL[Acc]),
        REMOVEFILTERS('Date'),
        'Date'[Date] <= maxdate
        
    )
VAR Subtract =
    CALCULATE (
        [BS],
        ALL(gl), VALUES(GL[Acc]),
        GL[Index] in FilteredIndexValues
        
    )
RETURN
   DayRT - Subtract

 

 

Pat

Microsoft Employee

View solution in original post

4 REPLIES 4
ppm1
Solution Sage
Solution Sage

The filter on the high granularity index column is the reason for the slowness. If the running total won't change with slicers, etc., it would be good to pre-calculate it in your query. The new WINDOW function may be a good approach too. However, below is a measure expression that is much faster. Please try it and report back. It calculates the running total from a day standpoint and then just subtracts any index values that came later on same day (if any). Note that I also used the Date column from your Date table in the visual, instead of the one from the GL table.

 

End_bal 2 = 
var thisindex = max(GL[Index])
var maxdate = MAX('Date'[Date])
VAR IndexValues = CALCULATETABLE(DISTINCT(GL[Index]), ALL(GL), VALUES(GL[Acc]), 'Date'[Date] = maxdate)
var FilteredIndexValues = FILTER(IndexValues, GL[Index] > thisindex)
VAR DayRT =
    CALCULATE (
        [BS],
        ALL(gl), VALUES(GL[Acc]),
        REMOVEFILTERS('Date'),
        'Date'[Date] <= maxdate
        
    )
VAR Subtract =
    CALCULATE (
        [BS],
        ALL(gl), VALUES(GL[Acc]),
        GL[Index] in FilteredIndexValues
        
    )
RETURN
   DayRT - Subtract

 

 

Pat

Microsoft Employee
193
Frequent Visitor

Hi,

 

@ppm1 , @Anonymous 

 

Both solutions solved my problem. @ppm1 interesting idea with window function, but I'm not sure how to implement it. 

Either way now speed is acceptable!

 

Big thanks for you both!

 

 

Ashish_Mathur
Super User
Super User

There is no file there.


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

Hi @193 

You can use the following code:

Measure = CALCULATE([BS],FILTER(ALL(GL),GL[Acc]=MAX(GL[Acc])&&[Index]<=MAX(GL[Index])))

vxinruzhumsft_0-1672105209612.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

Top Solution Authors