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! Request now

Reply
JL011
Regular Visitor

Aggregating latest value only for multiple IDs

Hi folks,

Been struggling with this one for a while now.  I am very close but could use a little help to finish this one up.  I am simply looking to take the last value of a duplicate ID in a time period and aggregate the results.  I am doing this with the measures at the end of this explanation of my challenge here.  Thanks you very much for taking the time to look at this any help woudl be very much appreciated.. 🙂 

I have a data set that looks like this:

ValidFromDate       |  Parent ID | Amount_hst   |  Probability_hst
--------------------------------------------------------------
4/8/2022  5:00        |     1           |  1            |      10

4/8/2022  5:30        |     1           |  1            |      20
5/8/2022  6:00        |     2           |  1            |      20
5/8/2022  6:15        |     3           |  1            |      20
6/8/2022  6:01        |     4           |  1            |      20
6/8/2022  6:05        |     5           |  1            |      20

This is the result I am trying to get and I mostly get this result but there is one important subdelty
Table results 

Date             |      Total Amount
------------------------------------
4/8/2022      |               1  
5/8/2022      |               2
6/8/2022      |               2

Card result = 5

the problem comes in when I try to build a stacked bar chart with the probability column as a legend.  The bar graph displays both entries and stacks the results showing a 1 and a 1 instead of just a single 1 on the line.
I only want the stacked bar chart to show the line with a probability of 20 because it was the latest entry in the month of April.
 
ValidFromDate       |  Parent ID | Amount   |  Probability
--------------------------------------------------------------

4/8/2022  5:00        |     1           |  1            |      10

4/8/2022  5:30        |     1           |  1            |      20



First Measure 

Max Date =
var _maxdate = CALCULATE(MAX('Table'[ValidFromDate]), VALUES('Table'[ParentId]))
return CALCULATE(SELECTEDVALUE('Table'[Amount__hst]),'Table'[ValidFromDate]=_maxdate)


Second Measure which uses the first measure 

Max Opportunity By Last Date =
var _table = SUMMARIZE('Opportunity (Historical)','Opportunity (Historical)'[ParentId], "_value", [Max Date])
 return SUMX( _table,  [_value])


Thank you so much for the help and happy to share more info if helpful.



1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @JL011 ;

You could try it.

Total Amount1 = 
var _maxdate = CALCULATE(MAX('Table'[ValidFromDate]),FILTER(ALL('Table'),EOMONTH([ValidFromDate],0)=EOMONTH(MAX('Table'[ValidFromDate]),0)))
return IF(MAX('Table'[ValidFromDate])=_maxdate, CALCULATE(SUM([Probability_hst]),FILTER(ALL('Table'),[ValidFromDate]=_maxdate)))
Max Opportunity By Last Date = 
var _table = SUMMARIZE('Table',[ParentId], "_value", [Total Amount1])
 return SUMX( _table,  [_value])

The final show:

vyalanwumsft_0-1658728555045.png


Best Regards,
Community Support Team _ Yalan Wu
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

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @JL011 ;

You could try it.

Total Amount1 = 
var _maxdate = CALCULATE(MAX('Table'[ValidFromDate]),FILTER(ALL('Table'),EOMONTH([ValidFromDate],0)=EOMONTH(MAX('Table'[ValidFromDate]),0)))
return IF(MAX('Table'[ValidFromDate])=_maxdate, CALCULATE(SUM([Probability_hst]),FILTER(ALL('Table'),[ValidFromDate]=_maxdate)))
Max Opportunity By Last Date = 
var _table = SUMMARIZE('Table',[ParentId], "_value", [Total Amount1])
 return SUMX( _table,  [_value])

The final show:

vyalanwumsft_0-1658728555045.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@JL011 , Refer if my blog on the same topic, how to correct that can help

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

 

or the video https://www.youtube.com/watch?v=7MRksDy0rWg

 

 

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 

Thank you for your response.  I will take a look when I get to the office later today.  I was able to find a solution that works for me late last night by creating a "month number" column and concatonating that column with the "parent ID" column.  That seems to work for my solution but it is not very elegant and or portable to other reports that I am running. 

I will let you know if your solution is an alternate way to solve the challenge I have.

Thannks!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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