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

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

Reply
Tlotly
Resolver II
Resolver II

Dax for calculating sum of all records with Max date

Good day

 

I have dataset with Group Nos, some have multiple meeting dates and some don't have, see example below. The groups all belong to one Centre. From the dates I needed to extract for each Group, a maximum date then use that in a measure to get a sum for a Centre. My desired answer is R8 460, which is all the highlighted groups in Red. 

Tlotly_0-1656575399294.png

 

To achieve this, I first created a column using DAX below to get the maximum dates for each group, which returns corrects results:

Max Meeting Date =
                                  var centre = CentreRepayments[centre code]
                                   var group1 = CentreRepayments[group no]
                                   var meetingperiod = CentreRepayments[Meeting Period]
var __result =
MAXX(
filter(
CentreRepayments,
CentreRepayments[Meeting Period] = meetingperiod
&&
CentreRepayments[group no] = group1
),
CentreRepayments[meeting_process_date]
)
return
__result
 
Then I used this column in a measure to sum all the Balances with max dates. This works perfectly at a Group level. 
The problem I'm facing is at a Centre Level, I can't get the correct Sum results. See DAX below. The reason being, Max date at a centre level is 30/06/2022. So the measure returns R 3010 which is for Groups A595 and A617. How do I correct this measure to also look at the other groups max dates?
 
monthlySavingsBal =
                                var maxmeetingdate = max(CentreRepayments[Max Meeting Date])
                                var minmeetingdate = min(CentreRepayments[Max Meeting Date])
                               var savings_bal = CALCULATE(SUM(CentreRepayments[group savings balance]),
FILTER(CentreRepayments,CentreRepayments[meeting_process_date] = maxmeetingdate))
return savings_bal
 
Any help will be highly appreciated.
Thank you
1 ACCEPTED SOLUTION
Tlotly
Resolver II
Resolver II

@amitchandak  Thank you for the quick response. The measures are still not working.

So I found a solution. I added a Flag column on the dataset:

MaxDateFlag = IF(CentreRepayments[meeting_process_date] = CentreRepayments[Max Meeting Date], "Y", "N")

 

Then used this on the measure. It's working perfectly:

monthlySavingsBal = CALCULATE(SUM(CentreRepayments[group savings balance]),
              FILTER(CentreRepayments,CentreRepayments[MaxDateFlag]= "Y"))
 
Thank you
 

View solution in original post

3 REPLIES 3
Tlotly
Resolver II
Resolver II

@amitchandak  Thank you for the quick response. The measures are still not working.

So I found a solution. I added a Flag column on the dataset:

MaxDateFlag = IF(CentreRepayments[meeting_process_date] = CentreRepayments[Max Meeting Date], "Y", "N")

 

Then used this on the measure. It's working perfectly:

monthlySavingsBal = CALCULATE(SUM(CentreRepayments[group savings balance]),
              FILTER(CentreRepayments,CentreRepayments[MaxDateFlag]= "Y"))
 
Thank you
 

@Tlotly , Thanks for updating. Good that it is solved. Kudos to you.

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
amitchandak
Super User
Super User

@Tlotly , try like

 

New meausre =
var _max = maxx(filter(allselected(CentreRepayments), CentreRepayments[centre code] = max(CentreRepayments[centre code])
&& CentreRepayments[group no] = max(CentreRepayments[group no]) ), CentreRepayments[Meeting_progress Date])
return
calculate(sum(CentreRepayments[Group Saving Balance]), filter(allselected(CentreRepayments), CentreRepayments[centre code] = max(CentreRepayments[centre code])
&& CentreRepayments[group no] = max(CentreRepayments[group no]) && CentreRepayments[Meeting_progress Date] = _max) )

or


New meausre =
var _max = maxx(filter(allselected(CentreRepayments), CentreRepayments[centre code] = max(CentreRepayments[centre code])
&& CentreRepayments[group no] = max(CentreRepayments[group no]) ), CentreRepayments[Meeting_progress Date])
return
calculate(sum(CentreRepayments[Group Saving Balance]), filter(CentreRepayments,CentreRepayments[Meeting_progress Date] = _max) )

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
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.

Top Solution Authors
Top Kudoed Authors