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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
shanestocks
Regular Visitor

Weighted Average sub-total not correct despite correct calculation?

Hi guys, I have a very simple task of finding a weighted average price of a "P CODE", which is determined by the use of "M CODE".

 

Please see below Power Pivot:

 

P CodeMeat CodeAct. (EUR)
P10000100826334.851
P10000RM00235.460
P10000RM00744.007
P10000 5.05368

 

Each meat code has it's own actual price, and the P code should represent the price of the meat * the quantity of the meat used. The meat codes are fine, but the P10000 total is not right. It's close, but it isn't right, and based on my calculations it should be 5.053749.

 

The raw data is as follows:

 

p_codem_codemeat_priceqty_used
P10000RM00744.0071,696
P10000RM00744.0071,539
P10000RM00744.0071,537
P10000RM00744.0071,534
P10000RM00744.0071,524
P10000RM00744.007977
P10000RM00744.0071,552
P10000100826334.5801,561
P10000RM00744.0071,608
P10000RM00744.0071,484
P10000RM00744.0071,465
P10000RM00744.0071,083
P10000RM00744.0071,570
P10000RM00744.0071,101
P10000100826334.5801,059
P10000100826334.5801,475
P10000100826334.580608
P10000100826334.5801,076
P10000100826334.580781
P10000100826334.5801,097
P10000100826334.5801,046
P10000RM00744.007551
P10000RM00744.0071,041
P10000RM00744.0071,583
P10000RM00744.007548
P10000100826334.5801,601
P10000100826334.5801,042
P10000100826334.5801,065
P10000RM00235.7621,069
P10000RM00235.7621,093
P10000100826334.5801,047
P10000100826334.5801,063
P10000100826334.5801,056
P10000100826334.5801,017
P10000100826334.5801,037
P10000100826334.5801,617
P10000100826334.5801,053
P10000100826334.5801,636
P10000100826334.5801,644
P10000100826334.5801,639
P10000100826334.5801,493
P10000100826334.5801,079
P10000100826334.580443
P10000100826334.5801,579
P10000RM00235.762556
P10000100826334.580937
P10000RM00235.7621,119
P10000100826334.580544
P10000100826334.5801,054
P10000100826334.580543
P10000100826335.9401,023
P10000100826335.9401,034
P10000100826335.940504
P10000100826335.940469
P10000RM00236.2401,003
P10000100826335.9401,086
P10000RM00236.105998
P10000RM00236.105995
P10000RM00236.1051,495
P10000RM00236.105998
P10000RM00236.105502
P10000RM00236.1051,001
P10000RM00236.060738
P10000RM00236.060498
P10000RM00236.060502
P10000RM00236.060502
P10000RM00236.0601,003
P10000RM00236.060502
P10000RM00236.0601,003
P10000RM00236.060502
P10000RM00236.0601,003
P10000RM00236.060997
P10000RM00236.060998
P10000RM00236.060300
P10000RM00236.060502
P10000RM00236.0601,003
P10000RM00236.060995
P10000RM00236.060499
P10000RM00236.060897
P10000RM00236.0441,003
P10000RM00236.0441,003
P10000RM00236.0441,000
P10000RM00236.0441,003
P10000RM00236.044498
P10000RM00236.044510
P10000RM00236.044511
P10000RM00236.044511
P10000RM00236.044502
P10000RM00236.044502
P10000RM00236.044502
P10000RM00236.044502
P10000RM00236.044510
P10000RM00236.0601,503
P10000RM00236.060502
P10000RM00236.0601,008
P10000RM00236.060511
P10000RM00236.0601,003
P10000RM00236.0601,003
P10000RM00236.060511
P10000RM00236.060510
P10000RM00236.0601,003
P10000RM00235.3631,003
P10000RM00235.3631,005
P10000RM00235.363511
P10000RM00235.363752
P10000RM00235.3631,008
P10000RM00235.3631,003
P10000100826335.940978
P10000100826335.940532
P10000RM00235.1671,083
P10000RM00235.1671,037
P10000RM00235.167903
P10000RM00235.1671,008
P10000RM00235.167511
P10000RM00235.167797
P10000100826335.940521
P10000100826335.940522
P10000RM00235.167903
P10000100826334.980897
P10000RM00234.9131,003
P10000RM00234.9131,503
P10000RM00234.913985
P10000RM00234.9131,003
P10000RM00234.913933
P10000100826334.980988
P10000RM00234.876978
P10000100826334.9801,012
P10000RM00234.8761,203
P10000RM00234.8761,198
P10000RM00234.876782
P10000RM00234.8761,203
P10000RM00234.876787
P10000RM00234.869541
P10000RM00234.8691,203
P10000RM00234.8691,003
P10000RM00234.8691,203
P10000100826334.9801,056
P10000RM00234.8691,203
P10000100826334.9801,993
P10000RM00234.8691,582
P10000100826334.9801,190
P10000RM00234.847782
P10000RM00234.847782
P10000RM00234.847802
P10000RM00234.847406
P10000RM00234.847812
P10000RM00234.847782
P10000RM00234.847812
P10000RM00234.847401
P10000RM00234.805406
P10000100826334.980396
P10000RM00234.805596
P10000100826334.9801,163
P10000RM00234.805752
P10000100826334.980752
P10000RM00234.8051,203
P10000RM00234.805812
P10000100826334.9801,168
P10000100826334.9801,131
P10000RM00234.6881,203
P10000RM00234.6881,166
P10000RM00234.688802
P10000RM00234.6881,203
P10000RM00234.688782
P10000100826334.9801,136

 

And the measure I am using is: 

 

=DIVIDE([req_cost_of_order],[used (KG)])

 

req_cost_of_order is SUMX of meat_price and qty_used.

used (KG) is SUM of qty_used.

 

Many thanks everyone.

2 REPLIES 2
v-yaningy-msft
Community Support
Community Support

Hi, @shanestocks 

According to your description, you want to get a weighted average price of a "P CODE",but the difficulty is that it's hard to understand how your requirement is realized, you can describe your requirement logically and completely (how the number 5.05368 is obtained), post the related MEASUREMENT (([REQ_COST_ OF_ order],[used (KG)).


Best Regards,
Yang
Community Support Team

Hi Yang, the measure is as follows:

 

=DIVIDE([req_cost_of_order],[used (KG)])

 

"req_cost_of_order" is a calculated column which multiplies qty_used * meat_price

"used (KG)" is a SUM of the qty_used column.

 

I also have two other columns that seperate the P CODE and the M CODE with the above table being a key that merges them both together.

 

I am thinking that at the P CODE level it should be the weighted average, and at the M CODE level it should simply be the meat_price?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.