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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
pmmarinou
Frequent Visitor

Faster way to calculate total balance as at the end of a year/current date

Dear Community,

 

I want to display the total of a column cummulative for each year. For example to calculate the value of 2023 and 2024 in the screenshot below:

pmmarinou_0-1728120966952.png

I use the following DAX, which give me the correct result.

Value =
CALCULATE(
    SUM(Transactions[Amount]),
    FILTER(
        ALL(DateTable),
        DateTable[Date] <=
            IF(
                YEAR(MAX(DateTable[Date])) = MAX(DateTable[Year]),
                MAX(DateTable[Date]),
                DATE(MAX(DateTable[Year]), 12, 31)  
            )
    )
)


However, when I show all of the investments transactions (around 15.000 rows) the report page is a bit slow when I filter or browse the matrix. Any suggestions to get the same result but faster meaning by doing less computations?

 

Thank you all in advance

 

1 ACCEPTED SOLUTION

@pmmarinou This will be a measure, here is a generic pattern:

 

VAR DailyAmount = 
	ADDCOLUMNS ( 
		ALL ( DateTable[Date] ), 
		"@Amount", [Amount] 
	)
VAR LastVisibleDate = 
	MAX ( DateTable[Date] )
VAR PreviousDates = 
	FILTER ( 
		DailyAmount,
		DateTable[Date] <= LastVisibleDate
	)
VAR RunningTotal = 
	SUMX ( PreviousDates, [@Amount] )
RETURN 
	Result 

See if this works?

 

 

 

View solution in original post

4 REPLIES 4
AntrikshSharma
Super User
Super User

@pmmarinou This part

 YEAR(MAX(DateTable[Date])) = MAX(DateTable[Year])

of your code is always going to evaluate to TRUE because both are fetching the Date and Year of the same year from the filter context, are you assuming it is referencing to row context created by FILTER?

 

To make it faster you can first pre compute the Amount with the help of 

ADDCOLUMNS ( ALL ( DateTable[Date] ), "Amount", [Amount] )

construct and then FILTER it accordingly, use variables to segregate the code into chunks.


 

 YEAR(MAX(DateTable[Date])) = MAX(DateTable[Year])

 

of your code is always going to evaluate to TRUE because both are fetching the Date and Year of the same year from the filter context, are you assuming it is referencing to row context created by FILTER?

 

Ok I edited it like this and it seems to work:

 

Value=
CALCULATE(
    SUM(Transactions[Amount]),
    FILTER(
        ALL(DateTable),
        DateTable[Date] <= MAX(DateTable[Date])
))

 

 


 

To make it faster you can first pre compute the Amount with the help of 

 

ADDCOLUMNS ( ALL ( DateTable[Date] ), "Amount", [Amount] )

 

construct and then FILTER it accordingly, use variables to segregate the code into chunks.


The DataTable and the Transaction Table are different. Can I return a new table from two tables using this function?

 

Thank you for your reply and help!

@pmmarinou This will be a measure, here is a generic pattern:

 

VAR DailyAmount = 
	ADDCOLUMNS ( 
		ALL ( DateTable[Date] ), 
		"@Amount", [Amount] 
	)
VAR LastVisibleDate = 
	MAX ( DateTable[Date] )
VAR PreviousDates = 
	FILTER ( 
		DailyAmount,
		DateTable[Date] <= LastVisibleDate
	)
VAR RunningTotal = 
	SUMX ( PreviousDates, [@Amount] )
RETURN 
	Result 

See if this works?

 

 

 

Using 

ADDCOLUMNS ( 
		ALL ( DateTable[Date] ), 
		"@Amount", [Amount] 
	)

 I lose all the other columns included in my transaction table needed for filtering

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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