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
Anonymous
Not applicable

How to calculate average of multiple categories

Hello all,

 

I want calculate average of multiple categories:

Here is the scenario

 

table_1

PlantStationMachineVolumeReject
Axx11503
Axy11505
Axz11501
Axt11507
Ayx12009
Ayq120010
Bxy12508
Bxt12507
Bxx12501

 

I have 2 factories 3 stations and several machines for each station.

Volume is equal to station's volume so the rows are duplicated

Rejects are basically the reject amount for each machine.

 

Below table is the explanation of what I want to tell above.

table_2

PlantStationVolumeRejectTotalRatio
Ax1501611%
Ay2001910%
Bx250166%

 

But the data format is as table_1

 

I want to calculate reject ratio as in table_2 for each plant_station pairs but I can't sum all volume because those values are duplicated in table_1

What I want to achieve is : create average for each plant_station pairs and divide to sum of reject totals.

 

How can I achieve that?

I'm quite new in DAX environment. I looked up some examples but I couldn't make it. Little explanation would be great!

 

Thanks in advance.

Cheers.

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @tyr, 

Here are the steps you can follow 

 1. Create measure. 

 

avg =  
CALCULATE(AVERAGE('Table'[Volume]),ALLEXCEPT('Table','Table'[Plant],'Table'[Station]))  

 

 

 
RejectTotal =  
CALCULATE(SUM('Table'[Reject]),ALLEXCEPT('Table','Table'[Plant],'Table'[Station])) 

 

 

Ratio =  
DIVIDE('Table'[RejectTotal],'Table'[avg])  
 

 

2. Result. 

Screenshot 2020-10-26 135357.png

 

You can downloaded PBIX file from here. 

 

Best Regards, 

Liu Yang 

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

5 REPLIES 5
v-yangliu-msft
Community Support
Community Support

Hi  @tyr, 

Here are the steps you can follow 

 1. Create measure. 

 

avg =  
CALCULATE(AVERAGE('Table'[Volume]),ALLEXCEPT('Table','Table'[Plant],'Table'[Station]))  

 

 

 
RejectTotal =  
CALCULATE(SUM('Table'[Reject]),ALLEXCEPT('Table','Table'[Plant],'Table'[Station])) 

 

 

Ratio =  
DIVIDE('Table'[RejectTotal],'Table'[avg])  
 

 

2. Result. 

Screenshot 2020-10-26 135357.png

 

You can downloaded PBIX file from here. 

 

Best Regards, 

Liu Yang 

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

FrankAT
Community Champion
Community Champion

Hi @Anonymous 

you can do it like this:

 

22-10-_2020_15-10-03.png

Reject Total = 
CALCULATE(
    SUM('Table'[Reject]),
    ALLEXCEPT('Table','Table'[Plant],'Table'[Station])
)

Ratio = DIVIDE([Reject Total],MIN('Table'[Volume]))

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

Anonymous
Not applicable

@FrankAT 

Thanks for the answer.

But I think I couldn't explain it clearly.

Table_2 is just explanation of what I need, table1 is actually how it is.

So it isn't  possible to work on table_2.

 

Thanks a lot for your effort,

 

Kind regards,

amitchandak
Super User
Super User

@Anonymous ,

volumn total = sumx(summarize(Table, Table[plant], table[station], "_1",calculate(Max(Table[Volume]))),[_1])

reject total = sum(Table[reject])

 

reject % = divide([reject total],[volumn total])

 

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

Anonymous
Not applicable

@amitchandak  thanks for the answer.

 

What is the purpose of "_1" ?

If it is suffix of stations, how can I generalise it?

In real data there is no pattern for station name unfortunately.

 

Thanks again.

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.