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
u92690
Frequent Visitor

SUM LASTDATE FOR EACH ELEMENT CONTEXT

Hi all, 

 

I'm struggling to find  the correct answer. I have a sheet with bank balances aggregated. What i want to do is:

 

"For each bank, look me up the last day within the month, and save that balance". So far what i've tried is:

 

Balance_end = CALCULATE([balance_sum],LASTDATE('Test last saldo'[Date])) 
 
which basically looks up the last day for each month in all the table and then sum all tha balances in that day, and does not work properly. Some how in need to introduce the context of the calculation, which is a bank level, to collect in tha sum all the balances, whatever it is the lastday for each one.
 
I attach the table example for reference.
 
 
Thank you
 
 
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @u92690 

 

If you want a measure, you could try this one

Last Balance Total = 
VAR _table = SUMMARIZE('Table','Table'[Bank],"Last_Date",MAX('Table'[Date]))
VAR _table2 = ADDCOLUMNS(_table,"Last Balance",SUMX(FILTER('Table','Table'[Bank]=[Bank]&&'Table'[Date]=[Last_Date]),'Table'[Balance]))
RETURN
SUMX(_table2,[Last Balance])

21112301.jpg

Add a calendar table to your model and create a relationship between it and balance table on date columns. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @u92690 

 

If you want a measure, you could try this one

Last Balance Total = 
VAR _table = SUMMARIZE('Table','Table'[Bank],"Last_Date",MAX('Table'[Date]))
VAR _table2 = ADDCOLUMNS(_table,"Last Balance",SUMX(FILTER('Table','Table'[Bank]=[Bank]&&'Table'[Date]=[Last_Date]),'Table'[Balance]))
RETURN
SUMX(_table2,[Last Balance])

21112301.jpg

Add a calendar table to your model and create a relationship between it and balance table on date columns. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

u92690
Frequent Visitor

I'm sorry but i don't think this solution fits my needs. I want to sum the last balance of the month for each bank, but i could have one bank whose last balance is the 01/25/2021 and another one is 01/31/2021. Therefore, I can't use the last date in the whole database for january, but the formula needs to catch the last balance for that bank no matter what the day is.

amitchandak
Super User
Super User

@u92690 , Based on what I got

 

closingbalancemonth(Sum('Table'[Value]), [balance_sum])

 

or

CALCULATE(Lastnonblankvalue('Test last saldo'[Date] , [balance_sum]) , filter(all('Date') , 'Date'[Month Year] = max('Date'[Month Year] )))

 

refer if needed

https://www.youtube.com/watch?v=yPQ9UV37LOU

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.