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

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

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.

Top Solution Authors