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
Anonymous
Not applicable

SUM distinct values with multiple filters

I have a table with the following columns

weir075_0-1593116839375.png

My goal is to SUM the km_length for the unique feature_id where the last end_date of new_state is "UNVERIFIED", which would be all of the highlighted rows in this image.

 

And preferably all in one measure

The total sum should be 2.54

 

Thanks

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

@Anonymous see if something like this will work for you.

Measure =
CALCULATE (
    SUMX (
        VALUES ( measurements[feature_id] ),
        CALCULATE ( MAX ( measurements[km_length] ) )
    ),
    measurements[new_state] = "UNVERIFIED"
)

View solution in original post

parry2k
Super User
Super User

@Anonymous I like to break measures and here is what you can do

 

 

Max Value = 
VAR __filter = FILTER( ALLEXCEPT ( Table, Table[Feature_Id ),
Table[New State] = "Unverified" )  
VAR __maxDate = CALCULATE ( MAX ( Table[Date] ), __filter )
RETURN
CALCULATE ( MAX ( Table[Value] ), 
__filter
Table[Date] = __maxDate
)

Sum of Max value = 
SUMX ( VALUES ( Table[Feature_Id] ), [Max Value] )

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

@Anonymous I like to break measures and here is what you can do

 

 

Max Value = 
VAR __filter = FILTER( ALLEXCEPT ( Table, Table[Feature_Id ),
Table[New State] = "Unverified" )  
VAR __maxDate = CALCULATE ( MAX ( Table[Date] ), __filter )
RETURN
CALCULATE ( MAX ( Table[Value] ), 
__filter
Table[Date] = __maxDate
)

Sum of Max value = 
SUMX ( VALUES ( Table[Feature_Id] ), [Max Value] )

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k That may be a solution, but there appears to be an error in your DAX after the RETURN statement

@Anonymous fixed, it was missing a column name.

 

The issue I see with @jdbuchanan71 solution is that it is giving you maximum value across all the dates, but not the value of most recent date. may be that is not the requirement.

 

for example, if one feature id has two records 

 

Jan 01st 1000

Jan 02nd 800

 

the measure will return 1000 whereas the  latest date is Jan 02nd and not sure if you are looking for 800 or 1000 in this case

 

FYI, otherwise @jdbuchanan71 solution is better.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k is correct, based on your sample I made the assumption that the km_length would be the same for the same feature_id regardless of date so MAX was safe.  If this is not the case you should look at his measures for your solution.

Anonymous
Not applicable

Yeah I managed to get @parry2k's working, am currently trying both solutions and looking for discrepancies between the two. Based on my original claim, I do think his answer is more correct and will accept his solution. Thank you both

jdbuchanan71
Super User
Super User

@Anonymous see if something like this will work for you.

Measure =
CALCULATE (
    SUMX (
        VALUES ( measurements[feature_id] ),
        CALCULATE ( MAX ( measurements[km_length] ) )
    ),
    measurements[new_state] = "UNVERIFIED"
)

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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