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
tonyclifton
Helper III
Helper III

Calculate value based on conditions

Hello community,

 

I've been trying for hours now with below messed up data to build a measure that will calculate the total cost for each stage:

 

MyMeasure = CALCULATE (
	MAX('Table'[Total Cost]), 
	FILTER(ALLSELECTED('Table'[Project] ), 'Table'[Project] = 'Table'[Project] )
)

 


MyMeasure works as expected for below example but my problem is that I only get the MAX value per Stage when in reality it should be the value where EndDate and ValueExistsForDate/YearMonth are closest or a value in column Cost per Stage exists.

tonyclifton_0-1695372280598.png

 

I hope you can help me out here.

Thank you very much.


Here's the raw sample data:

ProjectStageYearMonthCost per StageTotal CostEnd DateValueExistsForDate
ABCStage 12019-08322.362322.3622019-08-302019-08-01
ABCStage 12019-08  2020-03-27 
ABCStage 12019-08  2021-07-01 
ABCStage 12019-08  2022-06-10 
ABCStage 12019-08  2023-04-07 
ABCStage 12019-08  2023-09-22 
ABCStage 22020-03  2019-08-30 
ABCStage 22020-03322.362322.3622020-03-272020-03-01
ABCStage 22020-03  2021-07-01 
ABCStage 22020-03  2022-06-10 
ABCStage 22020-03  2023-04-07 
ABCStage 22020-03  2023-09-22 
ABCStage 32021-07  2019-08-30 
ABCStage 32021-07 322.3622020-03-272020-03-01
ABCStage 32021-07359.088359.0882021-07-012021-07-01
ABCStage 32021-07  2022-06-10 
ABCStage 32021-07  2023-04-07 
ABCStage 32021-07  2023-09-22 
ABCStage 42022-06  2019-08-30 
ABCStage 42022-06 322.3622020-03-272020-03-01
ABCStage 42022-06 359.0882021-07-012021-07-01
ABCStage 42022-06400.089400.0892022-06-102022-06-01
ABCStage 42022-06  2023-04-07 
ABCStage 42022-06  2023-09-22 
ABCStage 52023-04  2019-08-30 
ABCStage 52023-04 322.3622020-03-272020-03-01
ABCStage 52023-04 359.0882021-07-012021-07-01
ABCStage 52023-04 400.0892022-06-102022-06-01
ABCStage 52023-04400.089400.0892023-04-072023-04-01
ABCStage 52023-04  2023-09-22 
ABCStage 62023-09  2019-08-30 
ABCStage 62023-09 322.3622020-03-272020-03-01
ABCStage 62023-09 359.0882021-07-012021-07-01
ABCStage 62023-09 400.0892022-06-102022-06-01
ABCStage 62023-09 400.0892023-04-072023-04-01
ABCStage 62023-09421.583421.5832023-09-222023-09-01
1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @tonyclifton 

 

You can try the following methods.

Measure = 
Var _maxdate=CALCULATE(MAX('Table'[End Date]),FILTER(ALLEXCEPT('Table','Table'[Project],'Table'[Stage]),[Total Cost]<>BLANK()))
Return
CALCULATE(MAX('Table'[Total Cost]),FILTER(ALLEXCEPT('Table','Table'[Project],'Table'[Stage]),[End Date]=_maxdate))

vzhangti_0-1695610346496.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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-zhangti
Community Support
Community Support

Hi, @tonyclifton 

 

You can try the following methods.

Measure = 
Var _maxdate=CALCULATE(MAX('Table'[End Date]),FILTER(ALLEXCEPT('Table','Table'[Project],'Table'[Stage]),[Total Cost]<>BLANK()))
Return
CALCULATE(MAX('Table'[Total Cost]),FILTER(ALLEXCEPT('Table','Table'[Project],'Table'[Stage]),[End Date]=_maxdate))

vzhangti_0-1695610346496.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Awesome - works as expected. Took me while to get it working in my real environment but everything looks good now.
Thank you very much.

Thank you very much for the response. I will get back to you tomorrow as I'm currently not able to test with my data.

Helpful resources

Announcements
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!

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.

Top Solution Authors