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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate average of sum of production for each code

Hi,
I am having a date filter with values year, month and day. I am having a table with two columns - one with code (it has duplicates) and corresponding productions for the day selected. I tried the following measure but its wrong. 

 

CALCULATE(SUMX(VALUES('WASTAGE'[CODE]), AVERAGE('WASTAGE'[PRODUCTION])))

 

Can anyone help ?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi , I found a working solution to the above problem. Im adding it here just for reference.

NTest = 
var x = SUMX(SUMMARIZE(WASTAGE,(WASTAGE[CODE]), "Summ", sum(WASTAGE[PRODUCTION])), [Summ])
var y = count(WASTAGE[PRODUCTION])
return
x/y

NTest1 = 
VAR a = VALUES( WASTAGE[CODE] )
VAR Result = SUMX(a,[NTest])
RETURN 
IF(HASONEFILTER(WASTAGE[CODE]), [NTest], Result)

View solution in original post

3 REPLIES 3
qqqqqwwwweeerrr
Super User
Super User

Hi @Anonymous 

 

Can you provide more details about the data and expected output? Sample data. The problem statement is not very clear.

 

Regads

Anonymous
Not applicable

Hi @qqqqqwwwweeerrr , thanks for your response. 

ann_2024_0-1707076499049.png

Iam having a date filter. On selecting the date I want (4th-jan-2023 here) i want to calculate the total sum of averages of the production wrt to the code i.e ((800+800+.....+800)/7) + ((11776+ 11776+ .....11776)/5) => 800+11776 = 12567

I have tried the following measure , 

 

 

Total_production = SUMX(VALUES('WASTAGE'[CODE]), AVERAGE('WASTAGE'[PRODUCTION]))

 

 

and im getting 10,746 as the result for the above data which is wrong. Any help is appreciated.
Thanks.

Anonymous
Not applicable

Hi , I found a working solution to the above problem. Im adding it here just for reference.

NTest = 
var x = SUMX(SUMMARIZE(WASTAGE,(WASTAGE[CODE]), "Summ", sum(WASTAGE[PRODUCTION])), [Summ])
var y = count(WASTAGE[PRODUCTION])
return
x/y

NTest1 = 
VAR a = VALUES( WASTAGE[CODE] )
VAR Result = SUMX(a,[NTest])
RETURN 
IF(HASONEFILTER(WASTAGE[CODE]), [NTest], Result)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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