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
affan
Solution Sage
Solution Sage

Calculate Sum based on slicer and latest date if slicer value not in rows

Hello

 

I am having two tables Products Table.

ProductName
FP-001Finished Product 001
FP-002Finished Product 002
FP-003Finished Product 003
FP-004Finished Product 004

 

Cost Details Table

 

ProductMaterialPriceDatePrice Model
FP-001RM-0014.528-05-18A
FP-001RM-0025.328-05-18A
FP-001RM-0036.128-05-18 
FP-001RM-0012.415-06-18B
FP-001RM-0021.015-06-18B
FP-001RM-0035.015-06-18B
FP-001RM-0013.301-07-18 
FP-001RM-0025.201-07-18 
FP-001RM-0034.801-07-18 
FP-002RM-0035.715-06-18 
FP-002RM-0042.815-06-18A
FP-002RM-0084.815-06-18A

 

I need a measure to show the total cost of the Material for a Product. The complex part is that I have multiple cost lines for each raw material against a Product. I have to use a filter where the user can select the cost model. So if the user selects Cost Model "A" then the cost of Product "FP-001" should be all three materials cost against "A". But if there is a material which does not have a cost model A then its latest cost price by date should be included.

 

So in this case 

ProductMaterialPriceDatePrice Model
FP-001RM-0014.528-05-18A
FP-001RM-0025.328-05-18A
FP-001RM-0036.128-05-18 
FP-001RM-0012.415-06-18B
FP-001RM-0021.015-06-18B
FP-001RM-0035.015-06-18B
FP-001RM-0013.301-07-18 
FP-001RM-0025.201-07-18 
FP-001RM-0034.801-07-18 
FP-002RM-0035.715-06-18 
FP-002RM-0042.815-06-18A
FP-002RM-0084.815-06-18A

 

Product "FP-001" is having three materials RM-001, RM-002 and RM-003. When I select the slicer for Cost Model "A" I need to add the cost for RM-001 and RM-002 for the cost model, RM-003 does not have a line for this cost model so the line for RM-003 should be with the latest date. 

 

 

Please suggest, thanks in anticipation to your contributions.

 

Regards,

Affan

 

 

 

 

2 ACCEPTED SOLUTIONS
v-lili6-msft
Community Support
Community Support

hi,@affan

     After research, you may try to use this formula like below:

Measure = var mentral=CALCULATETABLE(SUMMARIZE(Cost,Cost[Product],Cost[Material],"date",CALCULATE(MAX(Cost[Date]))),ALLEXCEPT(Cost,Cost[Product]),Cost[Price Model]=BLANK()) return
var _maxdate =CALCULATE(MAXX(mentral,[date]),ALLEXCEPT(Cost,Cost[Product])) return
var _blankvalue=CALCULATE(SUM(Cost[Price]),ALLEXCEPT(Cost,Cost[Product]),Cost[Date]=_maxdate)return

var c=CALCULATE(SUM(Cost[Price]),FILTER(ALLEXCEPT(Cost,Cost[Product]),Cost[Date]=_maxdate&& NOT Cost[Material] IN VALUES(Cost[Material]))) return
CALCULATE(SUM(Cost[Price]))+c

result:

model A

20.PNG

 

Model B

21.PNG

here is pbix, please try it.

https://www.dropbox.com/s/7li701q8hbu995q/demo.pbix?dl=0

 

Best Regards,

Lin

Community Support Team _ Lin
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

Hi 

 

Thank you for the solution. This resolved my issue by taking the maxdate into variable.

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi,@affan

     After research, you may try to use this formula like below:

Measure = var mentral=CALCULATETABLE(SUMMARIZE(Cost,Cost[Product],Cost[Material],"date",CALCULATE(MAX(Cost[Date]))),ALLEXCEPT(Cost,Cost[Product]),Cost[Price Model]=BLANK()) return
var _maxdate =CALCULATE(MAXX(mentral,[date]),ALLEXCEPT(Cost,Cost[Product])) return
var _blankvalue=CALCULATE(SUM(Cost[Price]),ALLEXCEPT(Cost,Cost[Product]),Cost[Date]=_maxdate)return

var c=CALCULATE(SUM(Cost[Price]),FILTER(ALLEXCEPT(Cost,Cost[Product]),Cost[Date]=_maxdate&& NOT Cost[Material] IN VALUES(Cost[Material]))) return
CALCULATE(SUM(Cost[Price]))+c

result:

model A

20.PNG

 

Model B

21.PNG

here is pbix, please try it.

https://www.dropbox.com/s/7li701q8hbu995q/demo.pbix?dl=0

 

Best Regards,

Lin

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

Hi 

 

Thank you for the solution. This resolved my issue by taking the maxdate into variable.

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