Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
msfer
Advocate I
Advocate I

Cost calculation for products with bulk buying rules

Hi there 

 

I have the following data set where Product C and D doesn't have unit cost due to the bulk buying rules: 

 

 QtyUnit Cost Total Cost
A5210
B4312
C10  
D8  
E6530
C5  
D7  
C5  
D10  
Total 60  

 

This is my current formula which doesn't work, becuase it's a column the 2nd and 4th lines don't work. 

Cost1 = Switch( True(),

[Product]= "C" && [Qty] <= 5, [Qty]*5 ,

[Product]= "C",5*5 + ([Qty]-5)*2,

[Product]= "D" && [Qty] <= 2, [Qty]*3 ,

[Product]= "D", 2*5 + ([Qty]-2)*4,

[Qty]*[Unit Cost]

 

How would I go about fixing the [Qty] in to this formula to take in to account the sum of all Products for C and D?

 

I have tried bringing Qty in as a measure Sum([Qty]) which didn't work.
and also created this measure, which works perfectly except for the report table total (becasue it's a measure). So I am stuck there too. 

 Cost2 =

IF([Total Qty] <= 5 && MAX('Product'[Product Name])="C"[Total Qty]*5 ,
IF(MAX('Product'[Product Name])="C", 5*5 + ([Total Qty]-5)*2,
IF([Total Qty]<= 2 && MAX('Product'[Product Name])="D"[Total Qty]*3,
IF(MAX('Product'[Product Name])="D", 2*5 + ([Total Qty]-2)*4,
[Total Qty]*MAX('Product'[Unit Cost])
))))

 

Hoping someone can shed some light on this. 

 

Thank you in advance.

1 ACCEPTED SOLUTION

Hi, @msfer 

 

You can try the following methods.

Measure = 
Var _table=SUMMARIZE('Product','Product'[Product Name],"Cost2",[Cost2])
Return
SUMX(_table,[Cost2])

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @msfer 

 

What are your expectations?

vzhangti_0-1681717377236.png

Please provide more information.

 

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.

Hi v-zhangti

 

Thank you so much for your reply! 

 

The probelm is, the [Qty] needs to be taken in to account at the over all amount, not at a row level. That's why the measure calc (as oppoed to the column calc) works. 

 

I've created a PBIX, how do I attach it here. 

 

Basically: 

msfer_0-1681797259257.png

 

msfer_1-1681797277450.png

 

msfer_2-1681797306302.png

 

 

 

Hi, @msfer 

 

You can try the following methods.

Measure = 
Var _table=SUMMARIZE('Product','Product'[Product Name],"Cost2",[Cost2])
Return
SUMX(_table,[Cost2])

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

This worked perfectly. Thank you for your help @v-zhangti 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.